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

No comments yet. Be the first to leave a comment!

Leave a Comment

Your email address will not be published. Required fields are marked *