Loops Questions and Answers
Practice ModeShowing 10 of 25 questions
Q21
What will this code output: for i in range(1, 6): if i == 3: continue
print(i, end=" ")
Answer: Option A
Explanation: When i equals 3, continue skips the print statement, so 3 is not printed.
Q22
Which method is used to iterate over dictionary key-value pairs?
Answer: Option C
Explanation: items() method returns key-value pairs as tuples during dictionary iteration.
Q23
What is the output of: numbers = [1, 2, 3]
for num in numbers:
if num % 2 == 0:
break
print(num)
Answer: Option A
Explanation: The loop breaks when it encounters the first even number (2), so only 1 is printed.
Q24
How to reverse iterate through a list in Python?
Answer: Option B
Explanation: reversed() function or slicing [::-1] can be used to iterate through a list in reverse order.
Q25
What does the range() function with three parameters represent?
Answer: Option A
Explanation: range(start, stop, step) generates numbers from start to stop-1, incrementing by step.