Learn with Yasir

Share Your Feedback

Python for Loops – True or False Questions for Quick Practice

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.

🔍 True or False

🟢 Beginner

  1. A for loop in Python requires parentheses around its condition.
  2. Answer

    ❌ 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.


  3. The range() function includes both the start and stop values in its sequence.
  4. Answer

    ❌ False – range(start, stop) generates numbers from start (inclusive) to stop (exclusive). For example, range(1, 5) produces 1, 2, 3, 4.


  5. You can modify the list you're iterating over within a for loop without consequences.
  6. Answer

    ❌ 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.


  7. The loop variable in a for loop maintains its value after the loop completes.
  8. Answer

    ✅ True – The loop variable remains in scope after the loop finishes and retains its last assigned value from the loop.


🟡 Intermediate

  1. The else clause in a for loop executes only if the loop completes without encountering a break statement.
  2. Answer

    ✅ 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.


  3. In a nested for loop, a break statement in the inner loop will exit both the inner and outer loops.
  4. Answer

    ❌ False – A break statement only exits the innermost loop it's contained in. To exit multiple loops, you would need additional logic or flags.


  5. You can use a for loop to iterate over the key-value pairs of a dictionary using the items() method.
  6. Answer

    ✅ 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():`


🔴 Advanced

  1. A for loop in Python can only iterate over numerical ranges created by the range() function.
  2. Answer

    ❌ False – Python for loops can iterate over any iterable, including lists, tuples, strings, dictionaries, sets, and custom iterable objects - not just numerical ranges.


  3. List comprehensions are just syntactic sugar for equivalent for loops.
  4. Answer

    ✅ 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.


📚 Related Resources

🧠 Practice & Progress

Explore More Topics

📘 Learn Python

Tutorials, Roadmaps, Bootcamps & Visualization Projects

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




🧠 Python Advanced

Object-Oriented Programming in Python (OOP)

More...

🧠 Modules