Articles → Python → Range Function In Python
Range Function In Python
Purpose
Syntax
Parameter | Description |
---|
Start | This number specifies the starting number from which the sequence is going to start. This is optional if we specify the end parameter |
End | This number specifies the number where the sequence will end. This number is excluded from the sequence |
Step | This is the number by which the sequence gets incremented. This is optional. If this parameter is not specified, then the sequence gets incremented by 1 |
Example
print("Specifying start, end and step")
for x in range(2,21,2): # start = 3, end = 21, step 2
print (x)
print("Mention only start and end")
for x in range(0,6): # start = 0, end = 6
print (x)
print("Mention only end")
for x in range(10): # end = 10
print (x)
Output
Convert Range To List
Output