Usage of Range function Python
--------------------------------------
This will print sequence numbers from 0-4
0,1,2,3,4
for k1 in range(0,5):
print(k1)
0 -- Start number
5 -- End number .But 5 will not be included. range print (n-1) as index start from zero.
Below one print number from 10 - 14
for k2 in range(10,15):
print(k2)
Below one print number 10,12,14,16,18,20
for k3 in range(10,21,2):
print(k3)
for k4 in range(100,0,-25):
print(k4)
10 -- starting number
21 -- ending number
2 - step sequence
Below one print the values in list
k1 = list(range(0, 5))
k2 = list(range(10,15))
k3 = list(range(10,21,2))
k4 = list(range(100,0,-25))
print(k1)
print(k2)
print(k3)
print(k4)
list is function which will store the value in a list in sequence.
--------------------------------------
This will print sequence numbers from 0-4
0,1,2,3,4
for k1 in range(0,5):
print(k1)
0 -- Start number
5 -- End number .But 5 will not be included. range print (n-1) as index start from zero.
Below one print number from 10 - 14
for k2 in range(10,15):
print(k2)
Below one print number 10,12,14,16,18,20
for k3 in range(10,21,2):
print(k3)
for k4 in range(100,0,-25):
print(k4)
10 -- starting number
21 -- ending number
2 - step sequence
Below one print the values in list
k1 = list(range(0, 5))
k2 = list(range(10,15))
k3 = list(range(10,21,2))
k4 = list(range(100,0,-25))
print(k1)
print(k2)
print(k3)
print(k4)
list is function which will store the value in a list in sequence.
No comments:
Post a Comment