Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

range function with for loop in python

# Syntax - range(start, stop, step) - you must use integers, floats cannot be used

for i in range(3):
    print(i)
# output - automatically taken start = 0 and step = 1, we have given stop = 3 (excluding 3)

for i in range(0, 4):
    print(i)
# output - We have given start = 0 and stop = 4 (excluding 4), automatically taken step =1

for i in range(0, 5, 2):
    print(i)
# output - We have given start = 0, stop = 5 (excluding 5), step = 2

for i in range(0, -4, -1):
    print(i)
# output - We can go even backwards and also to negative numbers
 
PREVIOUS NEXT
Tagged: #range #function #loop #python
ADD COMMENT
Topic
Name
5+3 =