For loops and range
For loops and range
A for loop visits each item in an iterable. range creates a sequence of integers, commonly used for counting. The stop value is excluded. Use enumerate when you need both an index and an item.
Try it yourself
Change the example, run it, and explain the result in your own words. Then create one variation of your own.
Key idea
Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.
Code example
for number in range(1, 6):
print(number)
for index, topic in enumerate(["HTML", "CSS"], start=1):
print(index, topic)