Python range() Function
Returns a sequence of numbers starting from 0 (the default) and incrementing by 1 (the default) to the specified stop value. The stop value is not included in the range.
Syntax
Python
Copy Code
range(start, stop, step)
Parameters
Parameter | Description |
---|---|
start |
Required if step is provided. The index at which to start the range. Default is 0. |
stop |
Required. The index at which to end the range. |
step |
Required if start is provided. The distance between each step in the range. Default is 1. |
Example
Python
Copy Code
print('range from 10 to 15:') range10to15 = range(10, 15) for n in range10to15: print(n) print('range from 0 to 25 step by 5:') range0to25step5 = range(0, 25, 5) for n in range0to25step5: print(n)
Output
range from 10 to 15: 10 11 12 13 14 range from 0 to 25 step by 5: 0 5 10 15 20