A for loop iterates over any sequence: lists, strings, tuples, dictionaries, sets and ranges.
range(5) → 0, 1, 2, 3, 4
range(2, 10, 2) → 2, 4, 6, 8 (start, stop, step)
enumerate(list) gives the index and the item.
zip(a, b) loops over two lists together.
Loops can be nested.
💡 Key Takeaways: Python For Loops
Mastering Python For Loops helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Python For Loops Code Example
Python
for i in range(1, 6):
print(f"5 x {i} = {5 * i}")
names = ["Ali", "Sara", "Usman"]
scores = [88, 95, 72]
for name, score in zip(names, scores):
print(name, "scored", score)
for row in range(1, 4):
print("*" * row)
Free sign-in required · Google login available
Python For Loops Practice Exercises
Check what you learned in “Python For Loops”.
/ 3 solved
Fill in the blank
Loop over the numbers 0 to 4.
for i in (5):
✓ Correct!Not quite. Try again.
Multiple choice
What does range(2, 10, 2) produce?
✓ Correct!Not quite. Try again.
Code challenge
Print the 3 times table from 3 x 1 to 3 x 3 in the form "3 x 1 = 3".
Write the code in the live editor. Your answer is checked automatically.