List Quiz: 04
Python Lists Quiz - Advanced
Answer the following questions about Python lists by selecting the correct options:
Time Remaining: 10:00
1. What does this code output?
x = [i**2 for i in range(4)]
print(x)
A) [0, 1, 4, 9]
B) [1, 4, 9, 16]
C) [0, 1, 4]
D) Error
2. What does this code output?
x = [[1, 2], [3, 4]]
print(x[1][0])
A) 1
B) 3
C) 4
D) Error
3. What does this code output?
x = [0, 1, 2, 3, 4]
print(x[::2])
A) [1, 3]
B) [0, 2, 4]
C) [0, 1, 2]
D) Error
4. What does the following code output?
x = [1, 2, 3]
y = [4, 5]
print([a + b for a, b in zip(x, y)])
A) [5, 7]
B) [5, 7, 3]
C) [6, 8, 3]
D) Error
5. What does this code output?
x = [10, 20, 30, 40]
print(x[-3:-1])
A) [20, 30]
B) [30, 40]
C) [10, 20, 30]
D) Error
6. What will be the result of this code?
x = [5, 3, 8, 6]
y = sorted(x)
print(y == x)
A) True
B) False
C) Error
D) None
7. What will this code output?
x = [1, 2, 3]
y = x
y += [4]
print(x)
A) [1, 2, 3, 4]
B) [1, 2, 3]
C) [1, 2, 3, [4]]
D) Error
8. What does this code output?
x = [i for i in range(5) if i % 2 == 0]
print(x)
A) [1, 3]
B) [0, 2, 4]
C) [0, 1, 2, 3, 4]
D) Error
9. What does this code output?
x = [1, [2, 3], 4]
x[1][0] = 5
print(x)
A) [1, [5, 3], 4]
B) [1, [2, 5], 4]
C) [1, 5, 4]
D) Error
10. What does this code output?
x = [[i, i**2] for i in range(3)]
print(x)
A) [[0, 1], [1, 2], [2, 4]]
B) [[0, 0], [1, 1], [2, 4]]
C) [[1, 1], [2, 4], [3, 9]]
D) Error