Python MCQ and Answers – Part 19
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. What is the output of the following code?
not(1>2) not(1&1)
A FalseFalse
B FalseTrue
C TrueFalse
D TrueTrue
2. What is the output of 1+2**5//10
A 5
B 4
C 6
D 35
3. What is the output of the following code?
d = {"alex":23, "jean":24} print(list(d.keys()))
A (“alex”:23, “jean”:24)
B (“alex”, “jean”)
C [“alex”:23, “jean”:24]
D [“alex”, “jean”]
4. What is the output of the following code?
>>> t=(1,2,3,4) >>> t[1:3]
A (2, 3)
B (1, 2, 3)
C (2, 3,4)
D (1, 2)
5. What is the output of the following code?
def fun(i, l=[]): l.append(i) return l for i in range(3): print(fun(i))
A [1] [1, 2] [1, 2, 3]
B [1] [2] [3]
C [0] [0, 1] [0, 1, 2]
D [0] [1] [2]
6. What is the output of the following code?
t = (1, 2, 3, 4) l = [t[i] for i in range(0, len(t), 2)] print(l)
A [1, 3]
B [1, 3, 4]
C (1, 3)
D (1, 3, 4)
7. What is the output of the following code?
l = [1, 3, 6, 10] n = (x**2 for x in l) print(next(n), next(n))
A (1)
B (1, 3)
C (1, 9)
D (1, 9, 12, 20)
8. What is the output of the following code?
def fun(n): def multiply(x): return x * n return multiply a = fun(2) b = fun(2) print(a(b(2)))
A 2
B 4
C 6
D 8
9. Which of the following statements is true?
A You cannot chain multiple decorators in Python.
B Decorators don’t work with functions that take parameters.
C The @ symbol is useless when using decorators.
D None of the above
10. What is the output of the following code?
sum(1,2,3) sum([1,2,3])
A 6, 6
B 6, Error
C Error, Error
D Error, 6