Python For Loop

A for loop in python is used to iterable over sequences or collections. It can be programmed to go primarily over index or value. It uses an iterating variable that iterates over the next value from the iterable colection or range() function.

Python range() function

range() function makes an iterable object with the given start point, end point and step of traversal.

range(start, stop, step)

for loop syntax

    for item in collection:
        ...
                
    for i in range(number):
        ...
                                

for-else loop

else is executed if break is never executed or not present.

    for item in collection:
        if condition:
            statement
    else:
        statement