Labs ICT
โญ Pro Login

For Loop

1 min read | Python Tutorial
โญ

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

Python for Loop

The for loop in Python is used to iterate over sequences like lists, tuples, strings, or ranges. It follows a clean for variable in sequence syntax.

Basic for Loop Over a List

Looping through each item in a list.

fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

Looping with range()

range(start, stop, step) generates a sequence of numbers.

for i in range(1, 6):
    print(f"Number {i}")

Using enumerate()

enumerate() gives you both the index and the value during iteration.

colors = ["red", "green", "blue"]
for idx, color in enumerate(colors):
    print(f"{idx}: {color}")

Nested Loops

A loop inside another loop. Runs the inner loop fully for each outer iteration.

for i in range(1, 4):
    for j in range(1, 4):
        print(f"{i} x {j} = {i * j}")
    print("---")

๐Ÿงช Quick Quiz

What does range(5) generate?