For Loop In Python

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 collection or range() function.

Python Range() Function

range() function makes an iterable object with the given start point, endpoint, 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

Django training in Bangalore