Python MCQ and Answers – Part 13
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. What is the output of the following code?
print([i.lower() for i in "HELLO"])
A hello
B [‘hello’]
C ‘hello’
D [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
2. Suppose list1 = [0.5 * x for x in range(0, 4)]
, so list1 is:
A [0.0, 0.5, 1.0, 1.5, 2.0]
B [0.0, 0.5, 1.0, 1.5]
C [0, 1, 2, 3, 4]
D [0, 1, 2, 3]
3. What methods should the “iterator” object implement?
A __iter__()
B __iter__() and __next__()
C __iter__() and __super__()
D __iter__(), __super__() and __next__()
4. To add a new item to a list, what function do we use?
A list1.addEnd(3)
B list1.addLast(3)
C list1.append(3)
D list1.add(3)
5. What is the output of the following code?
print([if i%2==0: i; else: i+1; for i in range(4)])
A [0, 2, 2, 4]
B [1, 1, 3, 3]
C Error
D None of the above
6. What is the output of the following code?
x={} x[2]=1 x[1]=[2,3,4] print(x[1][1])
A 4
B 3
C [2,3,4]
D Error
7. To insert 3 at the second position in list1, what instruction do we use?
A list1.insert(2, 3)
B list1.insert(1, 3)
C list1.add(2, 3)
D list1.append(2, 3)
8. Which of the following is the same as
list(map(lambda x: x**-1, [1, 2, 3]))
A [x**-1 for x in [(1, 2, 3)]]
B [1/x for x in (1, 2, 3)]
C [1/x for x in [(1, 2, 3)]]
D Error
9. To remove the string “hello” from list1, what instruction do we use?
A list1.removeOne(“hello”)
B list1.removeAll(“hello”)
C list1.remove(hello)
D list1.remove(“hello”)
10. Suppose list1 is [3, 4, 1, 20, 5], so what is the output of list1.index(1)
?
A 0
B 1
C 2
D 4