30 Must Solve Python List MCQ for Coding Interviews

Welcome to this challenging Python List MCQ quiz! Here, we have collected 30 questions based on Python list which will cover basic to advanced concepts of list. This MCQ quiz will test your knowledge in list as well as level up your understanding in list.

Whether you’re a beginner or an experienced Python programmer, this quiz is perfect for coding interviews, competitive programming, and enhancing your knowledge in Python list. So, are you ready to score 30/30? Let’s see, how well do you really understand Python list? Let’s begin with question number 1.👇

1. What is a list in Python?
A. A fixed-size array
B. An unordered, immutable collection of items
C. An ordered, mutable collection of elements
D. An unordered set of key-value pairs
c
A list in Python is ordered collection of elements, which can be modified (mutable).
2. Which of the following data types can a list hold?
A. Only integers
B. Only strings
C. Only similar data types
D. Elements of any data type
d
Lists in Python can store mixed data types like integers, strings, floats, objects, other lists, etc.
3. Which of the following is not true about Python lists?
A. Lists are mutable.
B. Lists can grow or shrink in size.
C. Lists allow duplicate elements.
D. Lists are faster than tuples
d
Tuples are generally faster and more memory-efficient than lists.
4. What is the output of the following code?
my_list = [10, 20, 30, 40]
print(my_list[0])
A. 10
B. 20
C. 30
D. 40
a
Indexing starts at 0, so my_list[0] is the first element. Hence, the output is 10.
5. Which of the following is the correct way to create a list in Python?
A. list = (1, 2, 3)
B. list = [1, 2, 3]
C. list = {1, 2, 3}
D. list = <1, 2, 3>
b
Lists are defined using square brackets [].
6. Which method adds an element to the end of a list?
A. insert()
B. add()
C. append()
D. extend()
c
The append() method adds a single element at the end of the list.
7. What is the output of the following code?
a = [1, 2, 3]
a.append([4, 5])
print(a)
A. [1, 2, 3, 4, 5]
B. [1, 2, 3, [4, 5]]
C. [1, 2, 3, 4, [5]]
D. Error
b
The list [4, 5] is appended as a single element in the list named a.
8. How do you remove the first element with the value 3 from a list a = [1, 2, 3, 3, 4]?
A. a.remove(3)
B. a.pop(3)
C. del a[3]
D. a.delete(3)
a
The remove() function deletes the first occurrence of the value 3.
9. What will be the expected output of the following Python code?
a = [1, 2, 3]
b = a
b[0] = 100
print(a)
A. [1, 2, 3]
B. [1, 100, 3]
C. [100, 2, 3]
D. None
c
The line b = a means both point to the same list in memory.
10. What is the time complexity of accessing an element by index in a list?
A. O(1)
B. O(n)
C. O(log n)
D. O(n log n)
a
Accessing an element by index in a list is a constant-time operation.
11. What happens if you try to access an index that doesn’t exist in a list?
A. Returns None
B. Skips the element
C. Raises an IndexError
D. Creates the index automatically
c
Trying to access an index that’s out of range causes an IndexError.
12. What is the result of the following Python code?
x = [1, 2, 3]
y = x[:]
y.append(4)
print(x)
A. [1, 2, 3, 4]
B. [4, 2, 3]
C. [1, 2, 3]
D. None
c
x[:] creates a shallow copy. Changes to y don’t affect x.
13. What is the output of this code?
a = [1, 2, 3, 4, 5]
print(a[1:4])
A. [1, 2, 3]
B. [1, 2, 3, 4]
C. [2, 3, 4, 5]
D. [2, 3, 4]
d
Slicing includes the start index but excludes the end index, so it returns elements at positions 1, 2, and 3. Hence, the output is [2, 3, 4]
14. What does this code output?
list = [[]] * 3
list[0].append(1)
print(list)
A. [[1], [], []]
B. [[], [], [1]]
C. [[1, 1, 1]]
D. [[1], [1], [1]]
d
list = [[]] * 3 creates a list that repeats the same empty list object 3 times. So, it looks like: list = [same_list_ref, same_list_ref, same_list_ref]. All three elements are references to the same inner list. That means any change to one of them affects all. The line list[0].append(1) will append 1 to the list at index 0. Since all elements point to the same inner list, that change is reflected in all positions. Hence, the final output is [[1], [1], [1]]. Note that * with lists copies references, not the actual objects. All elements in the outer list refer to the same inner list. Therefore, mutating one element affects all of them.
15. What does this list comprehension return?
list = [i for i in range(5) if i % 2 == 0]
print(list)
A. [1, 3, 5]
B. [0, 1, 2, 3, 4]
C. [0, 2, 4]
D. [2, 4]
c
The expression filters even numbers between 0 and 4. Therefore, the output is [0, 2, 4].
16. What is the output of this Python code?
num_list = [1, 2, 3, 4]
print(num_list * 0)
A. [0, 0, 0, 0]
B. [1, 2, 3, 4, 1, 2, 3, 4]
C. [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
D. []
d
Multiplying a list by 0 gives an empty list.
17. What is the result of this operation?
num_list = [10, 20, 30, 40]
print(num_list[True] + num_list[False])
A. 10
B. 20
C. 30
D. 40
c
In Python, True equals 1 and False equals 0 when used as integers. So, the above expression evaluates to num_list[1] + num_list[0] which is 20 + 10 = 30.
18. What does this code output?
x = [1, 2, 3, 4]
y = x
x = x + [5]
print(y)
A. [1, 2, 3]
B. L[5, 1, 2, 3, 4]
C. [1, 2, 3, 4]
D. [1, 2, 3, 4, 5]
c
The line x = x + [5] creates a new list and assigns it to x, while y still references the original list. Therefore, the output is [1, 2, 3, 4]. If we used x.append(5) or x += [5], then y would be [1, 2, 3, 4, 5].
19. What does the below Python code output?
x = [1, 2, 3]
y = x
x = x + [4]
print(y[::-1])
A. [1, 2, 3]
B. [1, 2, 3, 4]
C. [4, 3, 2, 1]
D. [3, 2, 1]
d
y[::-1] creates a reversed version of the list y.
20. Which of the following creates a shallow copy of list a?
A. b = a
B. b = a[:]
C. b = list(a)
D. Both b and c
d
Both slicing and using list() create a shallow copy. While, b = a only creates a reference.
21. What is the output of this code?
my_list = [1, 2, 3, 4]
my_list[1:3] = [10, 20, 30]
print(my_list)
A. [1, 10, 20, 30, 4]
B. [10, 20, 30, 4]
C. [1, 10, 20, 3, 4]
D. [1, 10, 20, 30]
a
The slice assignment: my_list[1:3] = [10, 20, 30] replace elements from index 1 and index 2, (but not including index 3) with the new list [10, 20, 30], regardless of length. The original elements 2 and 3 are replaced with 10, 20, and 30.
22. What does this Python code output?
def extend_list(val, my_list=[]):
    my_list.append(val)
    return my_list

list1 = extend_list(1)
list2 = extend_list(2, [])
list3 = extend_list(3)
print(list1, list2, list3)
A. [1] [2] [3]
B. [1] [2] [1, 3]
C. [1, 3] [2] [1, 3]
D. [1, 2, 3] [2] [1, 2, 3]
c
In Python, default arguments are evaluated only once, when the function is defined, not each time it’s called. If you use a mutable default like a list (my_list=[]), the same list is shared across all calls where the argument isn’t explicitly passed. During the first call, my_list is not passed, so it uses the default list, which is [ ]. The argument 1 is appended and the list becomes [1]. So, list1 = [1]. During the second call, a new empty list is passed explicitly, so default list will not be used. The argument 2 is appended and the list becomes [2]. So, the list2 = [2]. During third call, again, my_list is not passed, so it uses the same default list from the first call, which already has [1]. Now 3 is appended in the default list and list becomes [1, 3]. Hence, the list3 = [1, 3] and list1 also points to the same list.
23. What is the expected output of the following Python code?
a = [1, 2, 3]
b = a
a[:] = [4, 5, 6]
print(b)
A. [1, 2, 3]
B. [1, 2, 3, 4, 5, 6]
C. [4, 5, 6, 1, 2, 3]
D. [4, 5, 6]
d
In the above code, the line b = a both point to the same list object [1, 2, 3] in the memory. The slice assignment a[:] = [4, 5, 6] replace all the elements in the original list with [4, 5, 6]. It does not create a new list. It modifies the contents of the existing list. Since b points to the same list, it will reflect the change.
24. What will the below Python code print?
a = [1, 2, 3]
b = [4, 5, 6]
print(a + b * 2)
A. [1, 2, 3, 8, 10, 12]
B. [1, 4, 9, 8, 10, 12]
C. [1, 2, 3, 4, 5, 6, 1, 2, 3]
D. [1, 2, 3, 4, 5, 6, 4, 5, 6]
d
The sub-expression b * 2 first evaluates to [4, 5, 6, 4, 5, 6]. Then, a + [4, 5, 6, 4, 5, 6] concatenates [1, 2, 3] with the expanded list. Hence, the final output is [1, 2, 3, 4, 5, 6, 4, 5, 6].
25. What will the expected result of the following program code?
a = [1, 2, 3]
b = a.copy()
a.append(4)
print(b)
A. [1, 2, 3, 4]
B. [1, 2, 3]
C. [4, 1, 2, 3]
D. None of the above
b
The line b = a.copy() creates an independent copy of the list, so changes to list a don’t affect the list b. If it were b = a, then b would be [1, 2, 3, 4].
26. What’s the result of the below Python code?
a = [1, 2, [3, 4]]
b = a[:]
a[2][0] = 99
print(b)
A. [1, 2, [3, 4]]
B. [1, 2, [99, 4]]
C. [1, 2, [3]]
D. [1, 2, [99]]
b
The line b = a[:] makes a shallow copy of the list a. The inner list [3, 4] is still shared between a and b.
27. What will this code snippet print?
lst = [1, 2, 3]
lst.insert(10, 4)
print(lst)
A. [1, 2, 3, 4]
B. IndexError
C. [4, 1, 2, 3]
D. [1, 2, 3, None]
a
The insert() function with an index greater than the length of list appends the item to the end.
28. If no error, what will be the expected output?
print([[]] * 2 == [[], []])
A. True
B. False
C. TypeError
D. None
a
Both lists have the same structure and values, so they are equal in value, even if not the same object.
29. Which of the following will cause an error?
A. [1, 2, 3] + [4]
B. [1, 2] * 2
C. [1, 2].append(3)
D. [1, 2] + 3
d
You can’t add a list and an integer. This is unsupported operand types. Use [1, 2] + [3].
30. What will be expected output of the following program code?
a = [1, 2, 3, 4, 5]
print(a[1:4][1:3][0])
A. 1
B. 2
C. 3
D. 4
c
a[1:4] → [2, 3, 4]. Next, [2, 3, 4][1:3] → [3, 4]. After that,
[3, 4][0] → 3.

Quiz Results

0
Total Questions
0
Correct Answers
0
Incorrect Answers
0%
Score
You can do better next time!