List Quiz: 05
Python Lists Quiz - Expert Level
Answer the following expert-level questions about Python lists:
Time Remaining: 10:00
1. What will this code output?
x = [1, 2, 3]
y = x[:]
y[0] = 4
print(x)
2. What does this code print?
x = [[0] * 3] * 3
x[0][0] = 1
print(x)
3. What does this code output?
x = [1, 2, 3, 4]
y = [a * b for a in x if a % 2 == 0 for b in x if b % 2 == 1]
print(y)
4. What does this code output?
x = [1, 2, 3]
x.extend(x)
print(x)
5. What does this code output?
x = [10, 20, 30, 40]
y = x[::-2]
print(y)
6. What will this code output?
x = [0, 1, 2]
y = [x] * 3
y[0][0] = 5
print(y)
7. What does this code output?
x = [10, 20, 30]
y = x.copy()
y.append(40)
print(x, y)
8. What does this code output?
x = [1, 2, 3]
y = [i for i in x if i % 2 == 0]
print(y)
9. What does this code output?
x = [3, 6, 9]
y = [a + b for a in x for b in range(3)]
print(y)
10. What does this code output?
x = [1, 2, 3]
print(sum([i**2 for i in x]))