Coding for All
Lesson 18: Counting with range()
Counting with range() Loop a set number of times.
1for number in range(5):
2 print(number)
Terminal
$ python3 main.py
0
1
2
3
4
Every line, explained
for number in range(5):
range(5) produces the numbers 0, 1, 2, 3, 4: it starts at 0 and stops just BEFORE 5. Combined with a for loop, this is how Python repeats something a set number of times.
print(number)
print(...) shows whatever is inside its round brackets in the terminal, then moves to a new line. It is written all in lowercase, and it needs both brackets. Runs five times, printing the current number each time. Notice it starts at 0, just like list indexes.