Python Tutorial Python Advanced Python References Python Libraries

Python for Keyword



The Python for keyword is used to create a for loop. The for loop is used to iterate over a given sequence and executes a set of statements for each element in the sequence.

Syntax

for iterating_var in sequence:
      statements

Flow Diagram:

Python For Loop

Example:

In the example below, for loop is used to print all elements of a given list.

MyList = [10, 20, 30, 40]

print("MyList contains:")
for i in MyList:
    print(i)

The output of the above code will be:

MyList contains:
10
20
30
40

❮ Python Keywords