range()
A sequence of whole numbers for loops. It starts at 0 and stops before the end.
Syntax
range(stop)range(start, stop)range(start, stop, step)
- Wrap it in list() to see the numbers.
Example
print(list(range(5))) print(list(range(2, 10, 3)))
Output:
[0, 1, 2, 3, 4] [2, 5, 8]
Common mistakes
- range(5) does not include 5. To count 1 to 5, use range(1, 6).