This function generates a list containing the values of an arithmetic progression, that is, a sequence of numbers such that the difference between adjacent numbers is always the same. There are three forms:
range(n
)
Returns the list [0, 1, 2, ...,
. Note that the result
never includes the value n
-1]
.
n
range(start
,
stop
)
Returns the list [
. The result never
includes the start
, start+1
, start
+2, ..., stop
-1]
value.
stop
range(start
,
stop
, step)
Returns the list [
, up to but not including the value of
start
, start
+step
, start
+2*step
, ...]
. The
value of stop
may be negative.
step
Examples:
>>> range(4) [0, 1, 2, 3] >>> range(4,9) [4, 5, 6, 7, 8] >>> range(10,104,10) [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] >>> range(5,-1,-1) [5, 4, 3, 2, 1, 0]