W3docs

Loop Tuples in Python

Learn every way to loop through a Python tuple: for loops, while loops, enumerate, range(len()), zip, nested tuples, and loop control statements.

Looping through a tuple lets you visit each element one at a time and act on it. Because tuples are immutable sequences — their contents cannot change — iterating over them is safe and straightforward. This page covers every common technique: for loops, while loops, enumerate(), range(len()), zip(), nested-tuple traversal, and loop-control with break/continue.

If you are new to tuples, read Python Tuples first. For the general loop syntax see Python For Loops and Python While Loops.

Using a for Loop

The simplest and most Pythonic way to iterate over a tuple is a for loop. Python steps through each element in order and assigns it to the loop variable.

Loop through a tuple with a for loop

python— editable, runs on the server

Output:

1
2
3
4
5

The loop ends automatically when it reaches the last element — no index arithmetic required.

Using a while Loop

A while loop gives you manual control over the index. It is useful when you need to advance or rewind by more than one step, or when the stopping condition depends on something other than the tuple length.

Loop through a tuple with a while loop

my_tuple = ('apple', 'banana', 'cherry')
i = 0

while i < len(my_tuple):
    print(my_tuple[i])
    i += 1

Output:

apple
banana
cherry

Always increment i inside the loop body, otherwise the loop runs forever.

Accessing the Index with enumerate()

When you need both the position and the value, use enumerate(). It wraps each element with its zero-based index and returns both together.

Loop through a tuple using enumerate

colors = ('red', 'green', 'blue')

for index, color in enumerate(colors):
    print(index, color)

Output:

0 red
1 green
2 blue

You can start counting from any number by passing a second argument:

Start enumerate from 1

colors = ('red', 'green', 'blue')

for index, color in enumerate(colors, start=1):
    print(index, color)

Output:

1 red
2 green
3 blue

enumerate() is preferred over range(len()) whenever you need both index and value, because it is more readable and avoids the extra indexing step.

Accessing the Index with range(len())

An older but still valid pattern uses range(len()) to generate the valid indices, then accesses each element by position.

Loop through a tuple using range and len

fruits = ('apple', 'banana', 'cherry')

for i in range(len(fruits)):
    print(i, fruits[i])

Output:

0 apple
1 banana
2 cherry

This approach is handy when you need to compare adjacent elements or modify a derived list based on position, because both the index and the value are available at the same time.

Iterating Over Nested Tuples

A tuple can contain other tuples. Use a nested for loop to reach the inner values.

Iterate over a nested tuple (matrix)

matrix = ((1, 2, 3), (4, 5, 6), (7, 8, 9))

for row in matrix:
    for value in row:
        print(value, end=' ')
    print()

Output:

1 2 3 
4 5 6 
7 8 9 

Each iteration of the outer loop gives you one inner tuple (row). The inner loop then steps through that inner tuple element by element.

You can also unpack the inner tuple directly in the loop header if the shape is fixed:

Unpack inner tuples while looping

points = ((0, 0), (1, 2), (3, 4))

for x, y in points:
    print(f'x={x}, y={y}')

Output:

x=0, y=0
x=1, y=2
x=3, y=4

This makes the code read almost like plain English and avoids row[0] / row[1] subscripts. For more on unpacking, see Unpack Tuples.

Looping Over Two Tuples in Parallel with zip()

zip() pairs up elements from two (or more) tuples by position and lets you unpack them in one loop.

Loop over two tuples in parallel

names = ('Alice', 'Bob', 'Carol')
scores = (95, 87, 92)

for name, score in zip(names, scores):
    print(name, score)

Output:

Alice 95
Bob 87
Carol 92

zip() stops as soon as the shortest tuple is exhausted, so mismatched lengths do not raise an error — they are silently truncated. If you need all pairs and want to fill gaps, use itertools.zip_longest() from the standard library instead.

Loop Control: break and continue

Stopping Early with break

break exits the loop immediately when a condition is met.

Stop a tuple loop early with break

numbers = (1, 2, 3, 4, 5, 6)

for n in numbers:
    if n == 4:
        break
    print(n)

Output:

1
2
3

The loop prints 1, 2, 3, then stops when it encounters 4.

Skipping Elements with continue

continue jumps to the next iteration without executing the remaining code in the loop body.

Skip even numbers using continue

numbers = (1, 2, 3, 4, 5, 6)

for n in numbers:
    if n % 2 == 0:
        continue
    print(n)

Output:

1
3
5

Only the odd numbers are printed; even numbers are silently skipped.

Building a List from a Tuple Loop

Because tuples are immutable, you cannot change them in place. A common pattern is to iterate over a tuple and collect results in a new list.

Create a list of squares from a tuple

numbers = (1, 2, 3, 4, 5)
squares = [n ** 2 for n in numbers]
print(squares)

Output:

[1, 4, 9, 16, 25]

The list comprehension iterates over the tuple just like a for loop and is more concise for simple transformations. See Python Tuples and Tuple Methods for more on working with tuple data.

When to Use Each Technique

GoalBest approach
Visit every element in orderfor item in my_tuple
Need the index tooenumerate()
Need precise index controlwhile loop or range(len())
Iterate two tuples togetherzip()
Traverse rows in a tuple of tuplesnested for loops
Stop early or skip elementsbreak / continue

Practice

Practice
Which built-in function returns both the index and value when looping over a Python tuple?
Which built-in function returns both the index and value when looping over a Python tuple?
Was this page helpful?