Explain the Python For Loops
Ask by ICSM Computer
Updated 24 Sep 2025
Basic Syntax
variable→ takes the value of each item in the iterable, one at a timeiterable→ a collection (like list, tuple, string, range, etc.)Examples
1. Loop through a list
Output:
2. Loop with
range()The
range()function generates a sequence of numbers.Output:
3. Loop with start and end in
range()Output:
4. Loop through a string
Output:
5. Using
break(stop the loop early)Output:
6. Using
continue(skip current iteration)Output:
7. Loop with
elsePython’s
forloops can have anelseblock that runs when the loop finishes without abreak.Output:
So,
forloops in Python are very flexible and often used withrange(), lists, dictionaries, and strings.