range()
function
Returns an immutable sequence of numbers. Commonly used in for loops.
Syntax
range(stop) range(start, stop, step)
Example
python
list(range(5)) # [0, 1, 2, 3, 4]
list(range(1, 6)) # [1, 2, 3, 4, 5]
list(range(0, 10, 2)) # [0, 2, 4, 6, 8]
list(range(10, 0, -1)) # [10,9,8,7,6,5,4,3,2,1]
for i in range(3):
print(i) # 0, 1, 2