Wednesday, April 25, 2012

The for Loop On A List Python Syntax

The general form of a for loop through a list in Python take the Linguistic form:


for iterator in List:
         Do Something with iterator

Example:

List = [1, 2, 3, 4]
for iterator in List:
         print iterator*2
Output:
2
4
6
8

No comments:

Post a Comment