There are different ways of using range() function.
range() function can accept 3 parameters as below:
range(start, stop, step)
However, if you type only one number inside range() function, it will smartly assume start is 0 (zero), step is 1 and stop is the number you’ve specified. So,
- You can specify only one number inside range’s parenthesis:
- i.e.: range(5)
- In this case, it will return a range of numbers from 0 to 5 (5 exclusive) increasing by 1 as below:
- 0, 1, 2, 3, 4
- You can specify two numbers inside range’s parenthesis:
- i.e.: range(2, 8)
- In this case, function will return a range of numbers from 2 to 8 (8 exclusive) increasing by 1 as below:
- 2, 3, 4, 5, 6, 7</n>
- You can specify all three numbers inside range’s parenthesis:
- i.e.: range(2, 13, 3)
- In this case, function will return a range of numbers from 2 to 13 (13 exclusive) increasing by 3 at each step as below:
- 2, 5, 8, 11