MCQ on List in Python – 3

Q1) Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is list1[-1]?

a) 3
b) 5
c) 1
d) 0

View Answer Answer:- d) 0

[-1] returns the last element in the list.

Q2) Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?

a) 0
b) 1
c) 4
d) 2

View Answer Answer:- d) 2

index(5) returns the position of the first 5 in the list.

Q3) Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?

a) 0
b) 1
c) 2
d) 4

View Answer Answer:- c) 2

count(5) returns the number of element 5 in the list.

Q4) Which of the following would give an error?

a) list1=[ ]
b) list1=[ ]*3
c) list1=[2,8,7]
d) None of the above

View Answer Answer:- d) None of the above

Q5) Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?

a) [3, 4, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [25, 20, 5, 5, 4, 3, 3, 1]
d) [3, 1, 25, 5, 20, 5, 4, 3]

View Answer Answer:- d) [3, 1, 25, 5, 20, 5, 4, 3]

reverse() returns the reverse element in the list.

Q6) Suppose listExample is [5, 3, 8, 15, 4], what is list1 after listExample.pop()?

a) [5, 3, 15, 4]
b) [5, 3, 8, 15, 4]
c) [3, 4, 5, 8, 15]
d) [5, 3, 8, 15]

View Answer Answer:- d) [5, 3, 8, 15]

pop() by default will remove the last element in the list.

Q7) Suppose listExample is [5, 3, 8, 15, 4], what is list1 after listExample.pop(2)?

a) [5, 3, 15, 4]
b) [5, 3, 8, 15, 4]
c) [3, 4, 5, 8, 15]
d) [5, 3, 2, 8, 15, 4]

View Answer Answer:- a) [5, 3, 15, 4]

pop() Removes the element at the position specified in the parameter.

Q8) Suppose listExample is [5, 3, 8, 15, 4], what is list1 after listExample.extend([12, 5])?

a) [5, 3, 8, 15, 4]
b) [12, 5, 5, 3, 8, 15, 4]
c) [5, 3, 8, 15, 4, 12, 5]
d) [ [5, 3, 8, 15, 4] [12, 5] ]

View Answer Answer:- c) [5, 3, 8, 15, 4, 12, 5]

Q9) Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

a) [0, 1, 2, 3]
b) [0, 1, 2, 3, 4]
c) [0.0, 0.5, 1.0, 1.5]
d) [0.0, 0.5, 1.0, 1.5, 2.0]

View Answer Answer:- c) [0.0, 0.5, 1.0, 1.5]

Q10) Select the correct options to join two lists in Python.

list1 = [‘a’, ‘b’, ‘c’, ‘d’]
list2 = [‘e’, ‘f’, ‘g’]

a) newList = list1 + list2
b) newList = list1 * list2
c) newList.extend(list1, list2)
d) newList = extend(list1, list2)

View Answer Answer:- a) newList = list1 + list2

Also See:- Python List MCQ– 4

Leave a Comment

Your email address will not be published. Required fields are marked *