Python 3 Tutorial · Chapter 13 of 22
Python For Loop
Repeat when the count is known.
for item in sequence visits each value. range(start, stop) is common for counting.
Nested for loops are used for tables and patterns.
For sample
Try it Yourself »
for i in range(1, 6):
print(i)
Classroom Tips
- range(1, 6) stops before 6.
- Prefer for when the collection size is known.