Notes / Python / Loops

Loops in Python — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Loops Python has two loop types: for (used to iterate over a sequence like a list, string, or range of numbers) and while (repeats while a condition is true).

Syntax

syntax
for item in iterable:
    # code
while condition:
    # code

Example

py
for i in range(1, 6):
    print(i, end=" ")

Output

output1 2 3 4 5

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Know that Python's for loop is really a "for-each" loop under the hood — it iterates over any iterable object, not just numeric ranges.
Back to notes Read full lesson →