Professional Documents
Culture Documents
For Statement
Its Syntax is
Example # loop to print value 1 to 10
for i in range (1, 11, 1):
print i,
Execution of the loop will result into
1 2 3 4 5 6 7 8 9 10
Let‟s understand the flow of execution of the statement:
The statement introduces a function range ( ), its syntax is
range(start, stop, [step]) # step is optional
range( ) generates a list of values starting from start till stop. Step if
given is added to the value generated, to get next value in the list.
Examples of range:
range(5):- [0,1,2,3,4]
range(1,5):- [1,2,3,4]
range(1,10,2):- [1,3,5,7,9]
range(10,0,-1):- [10,9,8,7,6,5,4,3,2,1]
Do this question
Q.Print all multiples of 13 that are smaller than 100. Use the range
function in the following manner: range (start, end, step) where "start"
is the starting value of the counter, "end" is the end value and "step" is
the amount by which the counter is increased each time