MCQ Hive stays free thanks to ads. Please disable your ad blocker for this site so content and features keep working.
Fundamental Programming
Control Structures
Beginner
Q
What does this Python code print?
L = [1, 2, 3, 4]
for x in L:
L.remove(x)
print(L)
A[1, 2, 3, 4]
BRuntimeError
C[2, 4]
D[]
Correct Answer:
C. [2, 4]
Explanation:
Removing items during iteration shifts later elements left, so every second element is skipped. Iterate over a copy (L[:]) instead.
ALSO KNOW (related points):
• How many values does Python's range(10, 0, -3) produce? → 4
• What does this Python code print?: for i in range(3):; pass; print(i) → 2