List Quiz: 02

Python Lists Quiz - Set 2

Python Lists Quiz - Set 2

Answer the following questions about Python lists by selecting the correct options:

Time Remaining: 10:00

1. What does this code print?

x = [5, 10, 15]
x[1] = 20
print(x)
A) [5, 10, 15] B) [5, 20, 15] C) [5, 10] D) Error

2. What is the result of this code?

x = [10, 20, 30, 40]
print(x[1:3])
A) [20, 30] B) [10, 20] C) [20, 30, 40] D) [10, 20, 30, 40]

3. What will be the result of the following code?

x = [5, 10, 15]
print(x * 2)
A) [5, 10, 15, 5, 10, 15] B) [10, 20, 30] C) Error D) None

4. What does the following code output?

x = [1, 2, 3]
x.extend([4, 5])
print(x)
A) [1, 2, 3, 4, 5] B) [[4, 5]] C) [1, 2, 3, [4, 5]] D) [1, 2, 3]

5. What does the following code return?

x = [10, 20, 30, 40]
print(x.index(30))
A) 2 B) 3 C) Error D) None

6. What does this code print?

x = [1, 2, 3]
x.pop()
print(x)
A) [1, 2] B) [1, 2, 3] C) [] D) Error

7. What will this code output?

x = [2, 3, 1, 5]
x.sort()
print(x)
A) [5, 3, 2, 1] B) [1, 2, 3, 5] C) [2, 3, 1, 5] D) Error

8. What does this code output?

x = ["apple", "banana", "cherry"]
print(x[::-1])
A) ["cherry", "banana", "apple"] B) ["apple", "banana", "cherry"] C) ["apple", "cherry", "banana"] D) Error

9. What is the output of this code?

x = [1, 2, 3]
print(sum(x))
A) 6 B) 5 C) 3 D) Error

10. What does this code output?

x = [1, 2, 3]
x.clear()
print(x)
A) [] B) [1, 2, 3] C) Error D) None