PyDocs

Nav

Python Runtime Services

range

  • range(stop, /)
  • range(start, stop, step=1, /)
range(stop) -> range object
range(start, stop[, step]) -> range object

Return an object that produces a sequence of integers from start (inclusive)
to stop (exclusive) by step.  range(i, j) produces i, i+1, i+2, ..., j-1.
start defaults to 0, and stop is omitted!  range(4) produces 0, 1, 2, 3.
These are exactly the valid indices for a list of 4 elements.
When step is given, it specifies the increment (or decrement).
Members of range

c

count
rangeobject.count(value) -> integer -- return number of occurrences of value

i

index
Raise ValueError if the value is not present.

s

start
The value of the start parameter (or 0 if the parameter was not supplied)
step
The value of the step parameter (or 1 if the parameter was not supplied)
stop
The value of the stop parameter
1 Example
>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
>>> list(range(0, 10, 3))
[0, 3, 6, 9]
>>> list(range(0, -10, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
>>> list(range(0))
[]
>>> list(range(1, 0))
[]
from the Python docs
See Also
No see-alsos for builtins/range
0 Notes
No notes for range