range
Construct a range, starting at 0
(inclusive), ending at end
(exclusive), with a step size of 1
.
Examples:
list(range(0))
returns[]
.list(range(1))
returns[0]
.list(range(2))
returns[0, 1]
.list(range(10))
returns[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
.
Note that range(x)
is equivalent to range(0, x, 1)
.
Since
0.6.0
Parameters
end value (exclusive) for this range
Throws
if end < 0
Construct a range, starting at start
(inclusive), ending at end
(exclusive), with a "step size" (i.e. difference between consecutive values) of step
.
If start > end
, then step
must be negative. Conversely, if start < end
, the step
must be positive. step
cannot be 0
.
Examples:
list(range(1, 23, 3))
returns[1, 4, 7, 10, 13, 16, 19, 22]
.list(range(20, 1, -2))
returns[20, 18, 16, 14, 12, 10, 8, 6, 4, 2]
.list(range(-2, -8, -1))
returns[-2, -3, -4, -5, -6, -7]
.list(range(3, 3, 7))
returns[]
. Indeed, for allx
, and for ally != 0
,range(x, x, y)
returns[]
.
Note that range(0, x, 1)
is equivalent to range(x)
.
Since
0.6.0
Parameters
start value for this range (inclusive)
end value for this range (exclusive)
step size for this range
Throws
when:
step == 0
start > end
andstep > 0
start < end
andstep < 0