1 Introduction
Although everyone often uses Python lists in daily work, do you think you have truly grasped its essence? This article lists ten basic Python list test questions, come and accept the challenge!
Without further ado, let’s get started!
2. Exercise 1
What is the output of the following code?
h = []
h.extend('code')
print(h)
The options are as follows:
A) ['code']
B) ['c', 'o', 'd', 'e']
C) []
D) Error
3. Exercise 2
What is the output of the following code?
b = [18, 20, 18, 22, 25]
b.remove(18)
print(b)
The options are as follows:
A) [18, 20, 22, 25]
B) [20, 22, 25]
C) [20, 18, 22, 25]
D) Error
4. Exercise 3
Choose the correct option in the blank space. The questions are as follows:
j = [40, 50, 60]
_______________
k.remove(50)
print(j)
Output:
[40, 60]
The options are as follows:
A) k = j.copy()
B) k = j
C) k = j[:]
D) k = list(j)
5. Exercise 4
What is the output of the following code?
d = [16, 32, 48, 64]
print(d.clear())
The options are as follows:
A) None
B) [16, 32, 48, 64]
C) []
D) Error
6. Exercise 5
What is the output of the following code?
k = [1, 2, 4, 5]
k.insert(3, 2)
print(k)
The options are as follows:
A) [1, 2, 2, 4, 5]
B) [1, 2, 3, 4, 5]
C) [1, 2, 4, 5, 3, 2]
D) [1, 2, 4, 2, 5]
7. Exercise 6
Choose the correct option in the blank space. The questions are as follows:
m = [19, 28, 37, 46, 55]
_______________
print(m)
Output:
[19, 28, 37, 46]
The options are as follows:
A) m.pop(5)
B) m.remove(4)
C) m.pop()
D) m.clear()
8. Exercise 7
Which of the following list methods does not return None?
A) pop()
B) reverse()
C) remove()
D) sort()
9. Exercise 8
What is the output of the following code?
g = [1, 2, 3, 4, 5]
a = g.pop(1)
print(g[-a])
The options are as follows:
A) 2
B) 4
C) 5
D) 3
10. Exercise 9
What is the output of the following code?
r = [10, 20, 30]
r.append([40])
print(r)
The options are as follows:
A) [10, 20, 30, 40]
B) [40]
C) [10, 20, 30, [40]]
D) [10, 20, 30]
11. Exercise 10
Choose the correct option in the blank space. The questions are as follows:
v = [53, 21, 97, 65, 34]
_______________
print(v)
Output:
[97, 65, 53, 34, 21]
The options are as follows:
A) sorted(v, reverse=True)
B) v.sort()
C) v.reverse()
D) v.sort(reverse=True)
12. Answer
The reference answer is as follows:
01. (B) 02. (C) 03. (B) 04. (A) 05. (D)
06. (C) 07. (A) 08. (B) 09. (C) 10. (D)