ScanSkill

range

This range() function returns a list of arithmetic progressions or numbers.

Syntax

range(start, stop[, step])

Here,

  • start: Required if the stop is used. An integer number. Default is 0.
  • stop: Required. An integer number.
  • step: Optional. An integer number. Default is 0.

Note: The full form returns a list of plain integers [start, start + step, start + 2 * step, …]. If step is positive, the last element is the largest start + i * step less than stop; if step is negative, the last element is the smallest start + i * step greater than stop. the step must not be zero (or else ValueError is raised).

Examples

  • With one argument
>>> x = range(10)
>>> for i in x:
...     print(i)
... 
0
1
2
3
4
5
6
7
8
9
  • With two arguments
>>> x = range(1, 11)
>>> for i in x:
...     print(i)
... 
1
2
3
4
5
6
7
8
9
10

>>> x = range(1, 0)
>>> for i in x:
...     print(i)
...
>>>
  • With three arguments
>>> x = range(1, 11, 2)
>>> for i in x:
...     print(i)
... 
1
3
5
7
9
>>> x = range(1, -11, -2)
>>> for i in x:
...     print(i)
... 
1
-1
-3
-5
-7
-9