PYTHON BASICSChapter 3 · Loops and iteration
Counting with range
The range() function is incredibly flexible. You can tell it where to start and where to stop. Remember, Python stops just before the stop number.
Worked example
How it reads
- range(1, 4) generates numbers starting at 1 and stopping before 4 (1, 2, 3)
- print(i) runs once for each of those numbers

Cloud tip: If you call range(stop), it starts at 0. If you call range(start, stop), it starts at start.


