Python MCQ and Answers – Part 14
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. suppose that list1 = [1, 2, 3, 1, 4, 5, 6, 1]
, so what is the output of the following code list1.count(1)
?
A 1
B 2
C 3
D 4
2. What is the output of the following code?
>>>t=(1,2,4,3) >>>t[1:3]
A (2, 4, 3)
B (2, 4)
C (1, 2, 4)
D (1, 2)
3. What is the output of the following code?
list1 = [1, 2, 3, 4, 5, 6] list1.reverse() print(list1)
A [3, 2, 1, 6, 5, 4]
B [6, 5, 4, 3, 2, 1]
C [6, 5, 4, 1, 2, 3]
D Display nothing
4. What is the output of the following code?
>>>tuple1 = (1, 2, 4, 3, 8, 9) >>>[tuple1[i] for i in range(0, len(tuple1), 2)]
A (1, 4, 8)
B [1, 4, 8]
C (2, 3, 9)
D [2, 3, 9]
5. What is the output of the following code?
def f(x, y, z): return x + y + z f(3, 20, 100)
A 320100
B 120
C 123
D Display nothing
6. Which of the following statements is true?
A Set is an unordered collection of elements.
B The elements of a set are unique.
C You can change the elements of a set unlike a tuple.
D All the answers are true
7. How can we change the value 3 by 2 in the following code?
x = {‘one’: 1, ‘two’: 3}
A x['two'] = 2
B x['two'] = '2'
C x[2] = 'two'
D x[1] = 'two'
8. What is the output of the following code?
>>>t = (1, 2) >>>2 * t
A [1, 2, 1, 2]
B [1, 1, 2, 2]
C (1, 1, 2, 2)
D (1, 2, 1, 2)
9. What is the output of the following code?
def f(x): x = x + [5] x = [1, 2, 3, 4, 5] f(x) print(len(x))
A 0
B 4
C 5
D An exception is thrown
10. What is the output of the following code?
>>>tuple1 = (1, 2, 4, 3) >>>tuple2 = (1, 2, 3, 4) >>>tuple1 < tuple2
A True
B False
C None
D Error