Main Tutorials

Python – How to loop a List

In this tutorial, we will show you how to use for-in-loop to loop a List in Python.


#example 1
frameworks = ['flask', 'pyramid', 'django'] #list

for temp in frameworks:
    print temp
    print "Python framework : %s" %temp

#example 2
numbers = [2,4,6,8,10] #list

for num in numbers:
    print num
    print "Number : %d" %num

Output


flask
Python framework : flask
pyramid
Python framework : pyramid
django
Python framework : django
2
Number : 2
4
Number : 4
6
Number : 6
8
Number : 8
10
Number : 10

References

  1. Python – How to loop a dictionary

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments