A for loop is used for iterating over a sequence like list, tuple, set.
loop is used to run the set of instruction again an again upto specified range
for loop are of two type in python-
- run according to range
- run on sequence(list,tuple,set)
program-
#list
l=[1,2,3,4,"Mytext"]
#simple for loop
print("Fisrt loop")
for i in range(4):
body
print(i)
#for each loop
print("Second loop")
for i in l:
body
print(i)
Fisrt loop
0
1
2
3
Second loop
1
2
3
4
Mytext