Python MCQ and Answers – Part 10
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. Which of the following statements will create a list?
A l = list()
B l = []
C l = list([1, 2, 3])
D All the answers are true
2. What is the output of the following code?
class MyClass:
def __init__(self, id):
self.id = id
id = 20
o = MyClass(10)
print o.id
A 20
B 10
C None
D Error
3. What is the output, if set1 = {1, 2, 3}?
set1.issubset(set1)
A True
B False
C Error
D None of the above
4. What is the output of the following code?
True = False
while True:
print(True)
break
A True
B False
C Error
D None
5. Suppose t = (1, 2, 4, 4), which of the following statements is incorrect?
A print(max(t))
B print(t[2])
C print(len(t))
D t[2] = 3
6. What is the output of the following code?
d = {"alex":30, "bob":35}
d["alex"]
A 30
B 35
C Error
D None
7. What is the output of the following code?
i = 1
while False:
if i%2 == 0:
break
print(i)
i += 2
A 1
B 1 3 5 7 …
C 2 4 6 8 …
D None of the above
8. What is the output when we run list(“hello”)?
A [‘olleh’]
B [‘llo’]
C [‘hello’]
D [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
9. What is the output of the following code?
class Point:
def __init__(self, x = 0, y = 0):
self.x = x
self.y = y
def __sub__(self, other):
x = self.x + other.x
y = self.y + other.y
return Point(x,y)
point1 = Point(30, 40)
point2 = Point(10, 20)
point3 = point1 - point2
print(point3.x, point3.y)
A 20 30
B 40 60
C 10 20
D 20 40
10. What is the output of the following code?
>>>a=("Hello")*3
>>>a
A (‘Hello’,’Hello’,’Hello’)
B The operator * not valid for tuples
C (‘HelloHelloHello’)
D Syntax error


