For Loop in Python

The for loop in Python is a control flow statement used to iterate over a sequence (like lists, tuples, dictionaries, sets, or strings) or any other iterable object. It is versatile and allows efficient traversal through elements in a sequence.

Key Points on For Loop:

Syntax of For Loop:

Syntax Example

for element in iterable:
            # Code to execute for each element

Example of For Loop in Python:

This example demonstrates a basic for loop that iterates over a list of numbers and prints each number.

Code Example

numbers = [1, 2, 3, 4, 5]
        for number in numbers:
            print(number)

Output

1
2
3
4
5

Detailed Explanation:

Using the for loop effectively enables efficient data handling and iteration in Python programs.