for loop in python by R4R Team

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)


output-

Fisrt loop
0
1
2
3
Second loop
1
2
3
4
Mytext


- In this program, there are two loop, first loop is simple for loop which run on range value starting from 0 to 3 while second for loop is a special kind of loop which run in list, and it run and select one by one item and print them.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!