How to use 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
# start, stop , step for i in range(1, 10, 2): print(i, end = " ") print() # only stop for i in range(5): print(i, end = " ") print() # using range for iteration t = [1, 2, 3, 4, 5] for i in range(len(t)): print(t[i], end = " ") print()
Output:
1 3 5 7 9 0 1 2 3 4 1 2 3 4 5
Subscribe
Login
Please login to comment
0 Discussion