List Quiz: 01
Python Lists Quiz
Answer the following questions about Python lists by selecting the correct options:
Time Remaining: 10:00
1. What will be printed by the following code?
my_list = [1, 2, 3, 4]
print(my_list[-1])
A) 1
B) 4
C) -1
D) IndexError
2. What will the following code output?
x = [1, 2, 3]
y = x
y.append(4)
print(x)
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) Error
D) None
3. What will the following code output?
x = [1, 2, 3]
y = x.copy()
y.append(4)
print(x)
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) Error
D) None
4. What is the output of this code?
x = [10, 20, 30]
print(x[1:])
A) [10, 20]
B) [20, 30]
C) [10, 20, 30]
D) [10]
5. What will be the output of the following code?
x = [1, 2, 3] + [4, 5]
print(x)
A) [1, 2, 3, 4, 5]
B) [4, 5]
C) Error
D) None
6. What will be printed by the following code?
x = [1, 2, 3]
x.insert(1, 4)
print(x)
A) [1, 2, 3]
B) [1, 4, 2, 3]
C) [4, 1, 2, 3]
D) Error
7. What will be the result of this code?
x = [1, 2, 3, 4, 5]
del x[2]
print(x)
A) [1, 2, 4, 5]
B) [1, 2, 3, 5]
C) [1, 3, 4, 5]
D) Error
8. What does the following code output?
x = [1, 2]
y = x * 3
print(y)
A) [1, 2, 1, 2, 1, 2]
B) [1, 2, 3]
C) Error
D) None
9. What will this code output?
x = [10, 20, 30]
x.remove(20)
print(x)
A) [10, 30]
B) [10, 20, 30]
C) Error
D) None
10. What will be the output of this code?
x = [1, 2, 3]
print(x.pop(1))
A) 1
B) 2
C) 3
D) None