Here are 100 output-based multiple-choice questions (MCQs) covering various levels and topics in Python programming. The answers are provided at the end in a table format.
Basic Python Concepts
1. What will be the output of the following code?
print(“Hello, World!”)
2. What will be the output of the following code?
print(“Python”[0])
3. What will be the output of the following code?
x = 5
y = 3
print(x / y)
4. What will be the output of this code?
x = 2
y = 4
print(x ** y)
5. What will be the output of the following code?
x = [1, 2, 3]
x[0] = 10
print(x)
6. What is the output of the following code?
x = “Python”
print(x[2:5])
7. What is the output of this code?
x = [1, 2, 3]
x.append(4)
print(x)
8. What will be printed when you run this code?
x = 10
y = “5”
print(x + int(y))
9. What will be the output of this code?
print(type(10))
10. What is the output of the following code?
x = 10
y = 3
print(x // y)
Intermediate Python Concepts
11. What will be the output of this code?
x = [1, 2, 3, 4]
print(x[1:3])
12. What will the following code output?
def multiply(x, y):
return x * y
print(multiply(2, 3))
13. What will be printed by the following code?
x = 4
y = 3
if x > y:
print(“x is greater”)
else:
print(“y is greater”)
14. What will be the output of this code?
def greeting(name):
print(“Hello ” + name)
greeting(“Alice”)
15. What is the output of the following code?
x = “apple”
print(x[::-1])
16. What will the following code print?
x = 10
y = 20
z = 30
print(x + y * z)
17. What will be the output of the following code?
def foo(x, y=5):
return x * y
print(foo(3))
18. What is the result of this code?
x = [1, 2, 3]
x.pop(1)
print(x)
19. What will the following code print?
x = {1, 2, 3}
x.add(4)
print(x)
20. What will be printed by the following code?
x = [1, 2, 3, 4]
x.remove(3)
print(x)
Advanced Python Concepts
21. What will be the output of the following code?
x = 5
y = 10
print(x == y)
22. What is the result of running this code?
x = [1, 2, 3]
y = x
y[0] = 10
print(x)
23. What will be printed by the following code?
try:
print(1 / 0)
except ZeroDivisionError:
print(“Division by zero”)
24. What is the output of this code?
x = {“name”: “Alice”, “age”: 25}
print(x[“age”])
25. What will the following code output?
x = “123”
print(int(x) + 1)
26. What is the result of the following code?
x = {1, 2, 3, 4}
x.remove(2)
print(x)
27. What will this code output?
def outer():
x = 5
def inner():
print(x)
inner()
outer()
28. What is the output of the following code?
x = [1, 2, 3, 4]
print(x[::2])
29. What is the output of this code?
x = {1, 2, 3}
x.add(4)
print(len(x))
30. What will be printed by this code?
x = [“a”, “b”, “c”]
print(x[1])
Additional Python Concepts
31. What will be printed by the following code?
x = (1, 2, 3)
print(type(x))
<class ‘dict’>
32. What will this code output?
x = “Python”
print(x.find(“t”))
33. What will be the result of the following code?
x = “Python”
print(x.upper())
34. What is the output of this code?
def multiply(x, y):
return x * y
print(multiply(4, 2))
35. What is the result of the following code?
x = {“apple”: 1, “banana”: 2}
print(x.get(“banana”))
Answers Table
| Qno | Answer |
| 1 | B) Hello, World! |
| 2 | A) P |
| 3 | A) 1.666 |
| 4 | B) 16 |
| 5 | B) [10, 2, 3] |
| 6 | C) tho |
| 7 | B) [1, 2, 3, 4] |
| 8 | A) 15 |
| 9 | A) <class ‘int’> |
| 10 | A) 3 |
| 11 | B) [2, 3] |
| 12 | A) 6 |
| 13 | A) x is greater |
| 14 | A) Hello Alice |
| 15 | A) elppa |
| 16 | A) 600 |
| 17 | A) 15 |
| 18 | A) [1, 3] |
| 19 | B) {1, 2, 3, 4} |
| 20 | B) [1, 2, 4] |
| 21 | B) False |
| 22 | B) [10, 2, 3] |
| 23 | A) Division by zero |
| 24 | B) 25 |
| 25 | A) 124 |
| 26 | B) {1, 3, 4} |
| 27 | A) 5 |
| 28 | B) [1, 3] |
| 29 | B) 4 |
| 30 | B) b |
| 31 | A) <class ‘tuple’> |
| 32 | B) 2 |
| 33 | A) PYTHON |
| 34 | A) 8 |
| 35 | B) 2 |
Python Functions and Control Flow
36. What is the output of the following code?
def add(a, b):
return a + b
print(add(3, 4))
37. What will be printed by this code?
def subtract(a, b=5):
return a – b
print(subtract(10))
38. What is the output of the following code?
def square(x):
return x ** 2
print(square(5))
39. What will be printed by the following code?
x = 10
if x > 5:
print(“Greater”)
else:
print(“Smaller”)
40. What will be the output of this code?
x = 3
if x > 3:
print(“Greater”)
elif x == 3:
print(“Equal”)
else:
print(“Smaller”)
41. What will be the result of the following code?
x = 10
y = 3
print(x % y)
42. What is the output of this code?
x = [10, 20, 30]
x.insert(1, 15)
print(x)
43. What is the result of this code?
x = 1
y = 2
z = 3
print(x + y * z)
44. What will be printed by this code?
x = 5
y = 6
x, y = y, x
print(x, y)
45. What is the output of the following code?
for i in range(3):
print(i, end=” “)
Lists, Tuples, and Dictionaries
46. What is the output of the following code?
x = [1, 2, 3]
y = x
y[0] = 10
print(x)
47. What will be printed by the following code?
x = [1, 2, 3]
x.pop(1)
print(x)
48. What will the following code output?
x = (10, 20, 30)
print(x[1])
49. What is the output of the following code?
x = {“name”: “Alice”, “age”: 25}
print(x.get(“name”))
50. What will be the output of the following code?
x = [1, 2, 3, 4]
x.extend([5, 6])
print(x)
51. What will the following code output?
x = {“apple”: 1, “banana”: 2}
del x[“apple”]
print(x)
52. What will the result of this code be?
x = [1, 2, 3, 4]
x.reverse()
print(x)
53. What will be printed by this code?
x = (10, 20, 30)
x = x + (40,)
print(x)
54. What is the output of this code?
x = {1, 2, 3}
x.add(4)
print(x)
String Manipulation
55. What will be printed by the following code?
x = “hello”
print(x[1:4])
56. What is the result of this code?
x = “Python”
print(x[2:5])
57. What is the output of this code?
x = “hello”
print(x.upper())
58. What will be printed by the following code?
x = “hello”
print(x[::2])
59. What will the following code output?
x = “hello”
y = x.replace(“e”, “a”)
print(y)
60. What will the result of this code be?
x = “hello”
print(len(x))
Answers Table
| Qno | Answer |
| 36 | B) 7 |
| 37 | B) 5 |
| 38 | B) 25 |
| 39 | A) Greater |
| 40 | B) Equal |
| 41 | B) 1 |
| 42 | A) [10, 15, 20, 30] |
| 43 | A) 9 |
| 44 | A) 6 5 |
| 45 | A) 0 1 2 |
| 46 | B) [10, 2, 3] |
| 47 | A) [1, 3] |
| 48 | B) 20 |
| 49 | A) Alice |
| 50 | A) [1, 2, 3, 4, 5, 6] |
| 51 | B) {“banana”: 2} |
| 52 | B) [4, 3, 2, 1] |
| 53 | A) (10, 20, 30, 40) |
| 54 | B) {1, 2, 3, 4} |
| 55 | B) ell |
| 56 | B) tho |
| Qno | Answer |
|---|---|
| 57 | A) HELLO |
| 58 | C) hlo |
| 59 | A) hallo |
| 60 | B) 5 |
Python Functions and Control Flow
61. What is the output of the following code?
def greet(name=”World”):
return “Hello ” + name
print(greet(“Alice”))
62. What will be printed by the following code?
x = 5
def test():
x = 10
print(x)
test()
63. What is the result of this code?
def square(x):
return x * x
result = square(3)
print(result)
64. What will be printed by the following code?
x = 2
y = 3
print(x ** y)
65. What will be the result of this code?
x = 10
y = 2
print(x // y)
66. What will be the output of this code?
x = [1, 2, 3]
y = [4, 5, 6]
print(x + y)
67. What will the following code print?
x = 5
y = 6
z = 10
print(x < y and y < z)
68. What is the output of this code?
x = 7
y = 2
print(x ** y)
69. What will be the result of this code?
x = 4
y = 5
if x > y:
print(“x is greater”)
else:
print(“y is greater”)
70. What will this code output?
x = “Python”
print(x[1:4])
Data Structures
71. What is the output of the following code?
x = [1, 2, 3, 4]
x.remove(3)
print(x)
72. What is the result of the following code?
x = [1, 2, 3]
print(x * 2)
73. What will be the output of this code?
x = (1, 2, 3)
y = list(x)
y[0] = 10
print(x)
74. What will this code output?
x = {1, 2, 3}
x.add(4)
print(x)
75. What is the output of this code?
x = {“apple”: 1, “banana”: 2}
print(x.keys())
76. What will the following code print?
x = {“a”: 1, “b”: 2}
x[“c”] = 3
print(x)
77. What is the output of this code?
x = [1, 2, 3]
y = [4, 5]
x.extend(y)
print(x)
78. What will be the result of the following code?
x = {1, 2, 3}
x.discard(2)
print(x)
79. What will this code output?
x = {“name”: “Alice”, “age”: 25}
print(x.get(“age”))
String Manipulation
80. What is the output of the following code?
x = “hello”
print(x[::-1])
81. What is the result of this code?
x = “Python”
print(x[1:4])
82. What will be the output of this code?
x = “hello”
print(x.replace(“e”, “a”))
83. What is the result of this code?
x = “hello”
y = x.upper()
print(y)
84. What will be printed by this code?
x = “Python”
print(x[::2])
85. What is the output of this code?
x = “Python”
y = x.split(“t”)
print(y)
86. What will this code output?
x = “apple”
print(x.find(“p”))
87. What will be the result of this code?
x = “Python”
print(x.startswith(“Py”))
88. What is the output of this code?
x = “Python”
print(x.lower())
89. What will the following code print?
x = “Python”
print(x[1:])
90. What is the result of this code?
x = ” hello “
print(x.strip())
Answers Table
| Qno | Answer |
| 61 | A) Hello Alice |
| 62 | A) 10 |
| 63 | B) 9 |
| 64 | B) 8 |
| 65 | A) 5 |
| 66 | A) [1, 2, 3,4, 5, 6] |
| Qno | Answer |
|---|---|
| 67 | A) True |
| 68 | B) 128 |
| 69 | B) y is greater |
| 70 | B) yth |
| 71 | B) [1, 2, 4] |
| 72 | A) [1, 2, 3, 1, 2, 3] |
| 73 | A) (1, 2, 3) |
| 74 | A) {1, 2, 3, 4} |
| 75 | A) dict_keys([‘apple’, ‘banana’]) |
| 76 | A) {“a”: 1, “b”: 2, “c”: 3} |
| 77 | A) [1, 2, 3, 4, 5] |
| 78 | A) {1, 3} |
| 79 | A) 25 |
| 80 | A) olleh |
| 81 | B) yth |
| 82 | A) hallo |
| 83 | A) HELLO |
| 84 | A) Pto |
| 85 | A) [‘Py’, ‘hon’] |
| 86 | A) 1 |
| 87 | A) True |
| 88 | A) python |
| 89 | A) ython |
| 90 | A) hello |
These questions help assess understanding of Python functions, control flow, data structures, and string manipulation.
Advanced Python Functions and Concepts
91. What will be the output of the following code?
def func(x, y=2):
return x * y
print(func(5))
92. What is the result of this code?
def add(a, b=10, c=5):
return a + b + c
print(add(3))
93. What will the following code print?
def outer():
x = 10
def inner():
print(x)
inner()
outer()
94. What will this code output?
def greet(name):
print(f”Hello, {name}”)
greet(“Python”)
95. What will be printed by this code?
def func(a, b):
a = 5
return a + b
print(func(3, 4))
96. What is the output of this code?
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n – 1)
print(factorial(4))
97. What will be the output of this code?
def func(a, b):
return a ** b
print(func(2, 3))
98. What will be printed by this code?
def my_func():
return 3 * 5
print(my_func())
99. What is the output of this code?
def counter():
count = 0
def increment():
nonlocal count
count += 1
increment()
return count
print(counter())
100. What is the output of the following code?
def add(x, y):
return x + y
result = add(“hello”, ” world”)
print(result)
Object-Oriented Programming
101. What will be the result of the following code?
class Animal:
def speak(self):
print(“Animal speaks”)
class Dog(Animal):
def speak(self):
print(“Dog barks”)
d = Dog()
d.speak()
102. What will be printed by this code?
class Car:
def __init__(self, make, model):
self.make = make
self.model = model
def __str__(self):
return f”{self.make} {self.model}”
car = Car(“Toyota”, “Corolla”)
print(car)
103. What is the output of this code?
class Person:
def __init__(self, name):
self.name = name
def greet(self):
print(f”Hello, {self.name}”)
p = Person(“Alice”)
p.greet()
104. What will be printed by this code?
class Parent:
def __init__(self):
self.value = 10
class Child(Parent):
def __init__(self):
super().__init__()
self.value += 5
def display(self):
print(self.value)
c = Child()
c.display()
105. What will be the output of this code?
class A:
def __init__(self):
self.x = 10
class B(A):
def __init__(self):
super().__init__()
self.x += 5
b = B()
print(b.x)
106. What will be printed by this code?
class Base:
def method(self):
print(“Base method”)
class Derived(Base):
def method(self):
print(“Derived method”)
d = Derived()
d.method()
107. What will be printed by this code?
class Vehicle:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def display(self):
print(f”Brand: {self.brand}, Model: {self.model}”)
car = Vehicle(“Honda”, “Civic”)
car.display()
108. What will be the output of this code?
class Animal:
def __init__(self):
self.type = “Mammal”
class Dog(Animal):
def __init__(self):
super().__init__()
self.breed = “Bulldog”
d = Dog()
print(d.type, d.breed)
109. What is the output of this code?
class Car:
def __init__(self, color):
self.color = color
def show(self):
print(self.color)
car = Car(“Red”)
car.show()
Advanced Python Concepts
110. What will be printed by this code?
x = [1, 2, 3]
y = [4, 5, 6]
z = x
z += y
print(z)
111. What will the output be for the following code?
x = “abc”
y = “def”
print(f”{x}{y}”)
112. What is the output of this code?
def decorator(func):
def wrapper():
print(“Before function”)
func()
print(“After function”)
return wrapper
@decorator
def say_hello():
print(“Hello”)
say_hello()
113. What will be the result of this code?
a = [1, 2, 3]
b = a
b[0] = 10
print(a)
114. What is the output of this code?
def func(x, y):
return x if x > y else y
print(func(5, 10))
115. What will be printed by this code?
x = {1, 2, 3}
x.add(4)
x.add(5)
x.remove(3)
print(x)
116. What is the output of this code?
x = “hello”
y = x.split(“e”)
print(y)
D) Error
117. What will be the output of this code?
x = 10
def outer():
x = 20
def inner():
global x
x = 30
inner()
print(x)
outer()
118. What will be the result of the following code?
x = [1, 2, 3, 4]
x.pop()
print(x)
119. What is the result of this code?
x = “Hello”
print(x[-1])
120. What is the output of this code?
x = “Python”
print(x[2:5])
Answers Table
| Qno | Answer |
| 91 | B) 10 |
| 92 | B) 18 |
| 93 | A) 10 |
| 94 | A) Hello, Python |
| 95 | B) 9 |
| 96 | A) 24 |
| 97 | B) 8 |
| 98 | A) 15 |
| 99 | A) 1 |
| 100 | A) hello world |
| 101 | B) Dog barks |
| 102 | A) Toyota Corolla |
| 103 | A) Hello, Alice |
| 104 | B) 15 |
| 105 | A) 15 |
| 106 | A) Derived method |
| 107 | A) Brand: Honda, Model: Civic |
| 108 | A) Mammal Bulldog |
| 109 | A) Red |
| 110 | A) [1, 2, 3, 4, 5, 6] |
| 111 | A) abcdef |
| 112 | A) Before function, Hello, After function |
| 113 | A) [10, 2, 3] |
| 114 | A) 10 |
| 115 | A) {1, 2, 4, 5} |
| 116 | A) [‘h’, ‘llo’] |
| 117 | A) 30 |
| 118 | A) [1, 2, 3] |
| 119 | A) o |
| 120 | A) tho |