range() function takes three arguments . It generates an arithmetic progression.
beg – First number of the range (default value is 0).
end – The end is exclusive in the range (end – 1 is the last number).
step – Difference b/w successive terms (default value is 1).
range object does lazy evaluation i.e. it stores the beg,end and step and generates the next number in when needed.
Yet, you can output the whole sequence at once using list ().
Example#1 :- Print all multiples of 3 under 10.
>>> for i in range(3,10,3):
... print(i)
...
3
6
9
Example#2 :- Passing negative step
>>> for i in range(100,10,-20):
... print(i)
...
100
80
60
40
20
Example#3 – Printing sequence at once.
>>> print(list(range(7))
[0, 1, 2, 3, 4, 5, 6]
>>> print(list(range(5,11))
[6, 7, 8, 9, 10]
>>> print(list(range(10,1,-2)))
[10, 8, 6, 4, 2]