Python for Loop

The most common loop in python is the for loop. It's constructed by combining the Python Keywords for and in explained earlier.

For loops are used for sequential traversal. The for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects. 

Syntax:

for iterator_var in sequence:
    statements(s)

Example: 

fruits = ['papaya', 'pineapple',  'litchi']
for fruit in fruits:
    print('Current fruit :', fruit)

Output:

Current fruit : papaya
Current fruit : pineapple
Current fruit : litchi
Tags