Home
MCQs by exam
Python Interview Lists
Data Science
Python Interview Lists MCQs – Data Science
28 multiple choice questions typical of the Python Interview Lists exam, with answers and explanations. Switch on practice mode to test yourself first.
print([x for x in [1, 2, 3] if x > 1])
A
[2, 3]
Correct answer
B
[1, 2]
C
[1, 3]
D
Error
print(len(max(['a', 'abc', 'ab'], key=len)))
A
1
B
3
Correct answer
C
2
D
Error
try:
[].pop()
except IndexError:
print('IndexError')
A
None
B
IndexError
Correct answer
C
[]
D
Error
print([3, 1].sort() == [1, 3])
A
True
B
None
C
False
Correct answer
D
Error
a = [1, 2, 3, 4]
a[1:3] = [5, 5]
print(a)
A
[1, 5, 4]
B
[1, 5, 5, 4]
Correct answer
C
[5, 5, 4]
D
Error
a = [1, 2, 3]
a.remove(2)
print(a)
A
[1, 3]
Correct answer
B
[2, 3]
C
[1, 2]
D
[3]
A
Deletes the whole list
B
Removes the first element
Correct answer
C
Sets the first element to None
D
Returns the first element
a = [1, 2, 3]
a.reverse()
print(a)
A
[1, 2, 3]
B
None
C
[3, 2, 1]
Correct answer
D
Error
print(sum([1, 2, 3]))
A
3
B
[1, 2, 3]
C
6
Correct answer
D
Error
a = [1, 2, 3]
b = a
b[0] = 99
print(a, b)
A
[99, 2, 3] [1, 2, 3]
B
[99, 2, 3] [99, 2, 3]
Correct answer
C
[1, 2, 3] [99, 2, 3]
D
[1, 2, 3] [1, 2, 3]
a = [1, 2, 3]
a.insert(1, 9)
print(a)
A
[9, 1, 2, 3]
B
[1, 9, 2, 3]
Correct answer
C
[1, 2, 9, 3]
D
[1, 2, 3, 9]
print([1, 2] * 2)
A
[1, 2, 1, 2]
Correct answer
B
[2, 4]
C
[1, 2, 2]
D
Error
print([10, 20, 30, 40][1:3])
A
[10, 20]
B
[20, 30, 40]
C
[10, 20, 30]
D
[20, 30]
Correct answer
print([1, 2, 2, 3].count(2))
A
1
B
3
C
0
D
2
Correct answer
A
deepcopy
B
copy
Correct answer
C
clone
D
shutil only
a = [1, 2, 3]
b = a.copy()
b[0] = 99
print(a, b)
A
[99, 2, 3] [99, 2, 3]
B
[99, 2, 3] [1, 2, 3]
C
[1, 2, 3] [99, 2, 3]
Correct answer
D
Error
print(sorted(['banana', 'pie', 'apple'], key=len))
A
['apple', 'banana', 'pie']
B
['banana', 'apple', 'pie']
C
['pie', 'apple', 'banana']
Correct answer
D
['pie', 'banana', 'apple']
A
The modified list
B
The appended item
C
None
Correct answer
D
The list length
A
O(1)
B
O(log n)
C
O(n^2)
D
O(n)
Correct answer
a = [1, 2, 3]
a.append(4)
print(a)
A
[1, 2, 3]
B
[1, 2, 3, 4]
Correct answer
C
[4, 1, 2, 3]
D
None
print([5, 6, 7].index(7))
A
1
B
3
C
0
D
2
Correct answer
A
list
B
set
Correct answer
C
tuple
D
str
A
sort() returns a new list; sorted() changes in place
B
They are identical
C
sorted() works only on strings
D
sort() changes the list in place; sorted() returns a new list
Correct answer
A
O(1)
Correct answer
B
O(n)
C
O(log n)
D
O(n log n)
print([1, 2, 3][::-1])
A
[3, 2, 1]
Correct answer
B
[1, 2, 3]
C
[1]
D
[3]
Practise on paper
Preparing for Python Interview Lists?
Make it your exam plan: see your progress in every subject and topic, set a daily goal and practise what you have not done yet.
Start my Python Interview Lists plan
Test yourself
Take a timed online test and get a certificate, or play today's quick quiz.
Online tests
Daily quiz