range() (Python)
range() generates a sequence of numbers, most often used to control how many times a for loop runs. It produces numbers on demand rather than storing them all in memory.
Python
range(stop) counts from 0 up to but not including stop. You can also pass a start and a step: range(start, stop, step).
Syntax
range(start, stop, step)Examples
Python
print(list(range(5)))
print(list(range(2, 10, 2)))Output:
[0, 1, 2, 3, 4]
[2, 4, 6, 8]