Labs ICT
๐ŸŽ“ SIWES/IT Login

For Loop

1 min read | Python Tutorial
๐ŸŽ“

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

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?