Iterating with for and range
Walk over numbers and sequences.
Walk Over Items
When you want to visit each value in turn, reach for a for loop. It pulls one item at a time and runs the body for each. 🚶
The for Shape
Write for, a loop variable, the word in, something to walk over, then a colon and an indented block.
for item in things:
print(item)All lessons in this course
- Making Choices with if/else
- Looping with while
- Iterating with for and range
- break, continue, and Early Exit