What is Range in Python
The range()
function returns a sequence of numbers, starting from 0( by default), and increments by 1 (by default), and stops before a specified number.
Syntax: range(start, stop, step)
- start : Optional. An integer number specifying at which position to start. Default valueis 0
- stop : Required. An integer number specifying at which position to stop (not included).
- step : Optional. An integer number specifying the incrementation. Default is 1
a = range(10) for i in a: print(i) print() x = range(7, 15) for i in x: print(i) print() a = range(7, 15, 2) for i in a: print(i)
Output:
0 1 2 3 4 5 6 7 8 9 7 8 9 10 11 12 13 14 7 9 11 13
Subscribe
Login
Please login to comment
0 Discussion