Python range() function
The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.
Syntax
1 2 3 |
range(stop) |
or
1 2 3 |
range(start, stop[, step]) |
Parameter
start: It is an optional parameter that represents an integer number specifying at which position to start, and by default, its value is 0
stop: It is an optional value that represents an integer number specifying at which position to end.
step: It is an optional value that represents an integer number specifying the incrementation, and by default, its value is 1.
Return
This function returns a sequence of numbers, starting from 0.
Example 1
1 2 3 4 5 6 7 8 |
# Python Program describing # the range() function val = range(10) print("The value returned: ") for num in val: print(num) |
Output
1 2 3 4 5 6 7 8 9 10 11 12 13 |
The value returned: 0 1 2 3 4 5 6 7 8 9 |