Name
range
Synopsis
range([start
,]stop
[,step
=1])
Returns a list of integers in arithmetic progression:
[start
,start
+step
,start
+2*step
, ...]
When start
is missing, it defaults to
0
. When step
is
missing, it defaults to 1
. When
step
is 0
,
range
raises ValueError
. When
step
is greater than 0
,
the last item is the largest
start
+
i
*
step
strictly less than stop
. When
step
is less than 0
,
the last item is the smallest
start
+
i
*
step
strictly greater than stop
. The result is
an empty list when start
is greater than
or equal to stop
and
step
is greater than 0
,
or when start
is less than or equal to
stop
and step
is less than 0
. Otherwise, the first item of the
result list is always start
.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.