ReferenceBuilt-in functions
range()
Whole numbers from start up to but not including stop, produced on demand.
Signature
range(start, stop, step)Parameters
| Name | Means |
|---|---|
start | the first number, 0 when omitted |
stop | one past the last |
step | how much to add each time |
Returns
A range object, not a list. It costs nothing until you loop over it.
Example
Python
print(list(range(4)))
print(list(range(2, 6)))
print(list(range(0, 10, 3)))
print(list(range(3, 0, -1)))Output
[0, 1, 2, 3] [2, 3, 4, 5] [0, 3, 6, 9] [3, 2, 1]