Python Range


Range function

The Range function determine the number of iterations to be executed by FOR statement. The Range function cycle start with 0 and ends with the n-1 value.

Examples

Print range values

>>> for c in range(3):
	print(c)

0
1
2

Print min and max values of the range

>>> print(range(5))
range(0, 5)

Print all values of an range into a list

>>> list(range(7))
[0, 1, 2, 3, 4, 5, 6]

Print a specified range

>>> x = [1, 2, 3, 4, 5]
>>> for i in range(3):
	print(i, x[i])

0 1
1 2
2 3