250+ TOP MCQs on Python Lists and Answers

Python Programming Questions & Answers on “Lists”.

1. 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]
Answer: d
Clarification: Execute in the shell to verify.

2. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34, 5])?
a) [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
b) [1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
c) [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
d) [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
Answer: a
Clarification: Execute in the shell to verify.

3. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?
a) [3, 4, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]
Answer: c
Clarification: pop() removes the element at the position specified in the parameter.

4. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?
a) [3, 4, 5, 20, 5, 25, 1]
b) [1, 3, 3, 4, 5, 5, 20, 25]
c) [3, 5, 20, 5, 25, 1, 3]
d) [1, 3, 4, 5, 20, 5, 25]

Answer: a
Clarification: pop() by default will remove the last element.

5. What will be the output of the following Python code?

  1. >>>"Welcome to Python".split()

a) [“Welcome”, “to”, “Python”]
b) (“Welcome”, “to”, “Python”)
c) {“Welcome”, “to”, “Python”}
d) “Welcome”, “to”, “Python”
Answer: a
Clarification: split() function returns the elements in a list.

6. What will be the output of the following Python code?

  1. >>>list("a#b#c#d".split('#'))

a) [‘a’, ‘b’, ‘c’, ‘d’]
b) [‘a b c d’]
c) [‘a#b#c#d’]
d) [‘abcd’]
Answer: a
Clarification: Execute in the shell to verify.

7. What will be the output of the following Python code?

  1. myList = [1, 5, 5, 5, 5, 1]
  2. max = myList[0]
  3. indexOfMax = 0
  4. for i in range(1, len(myList)):
  5.     if myList[i] > max:
  6.         max = myList[i]
  7.         indexOfMax = i
  8.  
  9. >>>print(indexOfMax)

a) 1
b) 2
c) 3
d) 4
Answer: a
Clarification: First time the highest number is encountered is at index 1.

8. What will be the output of the following Python code?

  1. myList = [1, 2, 3, 4, 5, 6]
  2. for i in range(1, 6):
  3.     myList[i - 1] = myList[i]
  4.  
  5. for i in range(0, 6): 
  6.     print(myList[i], end = " ")

a) 2 3 4 5 6 1
b) 6 1 2 3 4 5
c) 2 3 4 5 6 6
d) 1 1 2 3 4 5
Answer: c
Clarification: Execute in the shell to verify.

9. What will be the output of the following Python code?

  1. >>>list1 = [1, 3]
  2. >>>list2 = list1
  3. >>>list1[0] = 4
  4. >>>print(list2)

a) [1, 3]
b) [4, 3]
c) [1, 4]
d) [1, 3, 4]
Answer: b
Clarification: Lists should be copied by executing [:] operation.

10. What will be the output of the following Python code?

  1. def f(values):
  2.     values[0] = 44
  3.  
  4. v = [1, 2, 3]
  5. f(v)
  6. print(v)

a) [1, 44]
b) [1, 2, 3, 44]
c) [44, 2, 3]
d) [1, 2, 3]

Answer: c
Clarification: Execute in the shell to verify.

programming questions on Python,

Leave a Comment

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

Scroll to Top