1print("using start, stop, and step arguments in Python range() function")
2print("Printing All odd numbers between 1 and 10 using range()")
3for i in range(1, 10, 2):
4 print(i, end=', ')
1# range(start, stop, step)
2 # start = (can be ommitted) index to begin at (INCLUSIVE)
3 # stop = generate numbers up to, but not including this number (EXCLUSIVE)
4 # step = (can be omitted) difference between each number in the sequence
5
6# idx: 0 1 2 3 4
7# arr: 19 5 3 22 13
8
9arr = [19,5,3,22,13]
10
11# range(stop)
12for i in range(len(arr)):
13 print(arr[i]) # prints: 19, 5, 3, 22, 13
14
15# range(start, stop)
16for i in range(2, len(arr)):
17 print(arr[i]) # prints: 3, 22, 13
18
19# range(start, stop, step)
20for i in range(0, len(arr), 2):
21 print(arr[i]) # prints: 19, 3, 13
22
23# reverse:
24for i in range(len(arr)-1, -1, -1):
25 print(arr[i])
1# if numbers are same in the range function then,
2# the range function outputs empty range
3# this is because, there are no integers b/w n and n
4for i in range(1,1):
5 print("runs")
6
7# prints nothing
8
1>>> def range1(start, end):
2... return range(start, end+1)
3...
4>>> range1(1, 10)
5[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]