For Loop in Python

For Loop in Python programming is a control flow statement that allows code to be repeatedly executed and repeat a specific block of code for a fixed number of times.

General form of For Loop


for num in range(range):
    do this

For Loop Printing 1 to 9 Numbers

Program

for num in range(10): #loop looping from 0 to 10 Not
    print(num) #Included 10, and printing.
Output
0
1
2
3
4
5
6
7
8
9

For Loop Printing 1 to 9 Numbers Another Method

Program

for num in range(1, 10): #loop looping on given Range 1 to 10 Not
    print(num) #Including 10, and printing.
Output
1
2
3
4
5
6
7
8
9

Program For Loop using If Statement
Program

for a in range(11): #loop looping from 0 to 10.
    if a > 4 and a < 8: #if 'a' value greater then 4 And less then 8 then
        print(a) #print 'a' value.
Output
5
6
7