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

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments