For Loop

for Loop is used to iterate a variable over a sequence(i.e., list or string) in the order that they appear.

Syntax:

for <variable> in <sequence>:

Output:

1
 
7
 
9

Explanation:

Firstly, the first value will be assigned in the variable.

Secondly all the statements in the body of the loop are executed with the same value.

Thirdly, once step second is completed then variable is assigned the next value in the sequence and step second is repeated.

Finally, it continues till all the values in the sequence are assigned in the variable and processed.

#Program to display table of Number

num=2
for a in range (1,6):
    print (num * a)

Output:

2  
4
6  
8
10

#Program to find sum of Natural numbers from 1 to 10.

sum=0
for n in range(1,11):
    sum += n
print(sum)

Output:

55