Test your knowledge of Python for loops with true or false questions. A fast and effective way for beginners to reinforce concepts like syntax, iteration, and loop behavior.
❌ False – Python for loops use the syntax `for item in iterable:` without parentheses. Parentheses are used in some other languages but not in Python's for loops.
❌ False – range(start, stop) generates numbers from start (inclusive) to stop (exclusive). For example, range(1, 5) produces 1, 2, 3, 4.
❌ False – Modifying a list while iterating over it can lead to unexpected behavior, including skipped elements or infinite loops. It's generally safer to iterate over a copy of the list if modifications are needed.
✅ True – The loop variable remains in scope after the loop finishes and retains its last assigned value from the loop.
✅ True – The else clause in Python's for loops is unique and executes only when the loop exhausts the iterable (for loop) or the condition becomes false (while loop) without hitting a break statement.
❌ False – A break statement only exits the innermost loop it's contained in. To exit multiple loops, you would need additional logic or flags.
✅ True – dict.items() returns an iterable view of (key, value) pairs, allowing you to iterate over both simultaneously: `for k, v in my_dict.items():`
❌ False – Python for loops can iterate over any iterable, including lists, tuples, strings, dictionaries, sets, and custom iterable objects - not just numerical ranges.
✅ True – List comprehensions are indeed a more concise way to write certain for loops that build lists, and they compile to similar bytecode as the equivalent explicit for loop implementation.
Tutorials, Roadmaps, Bootcamps & Visualization Projects