Last modified: Jan 27, 2026 By Alexander Williams

Python Tuple of Tuples Guide and Examples

A tuple of tuples is a powerful Python data structure. It stores multiple tuples inside one main tuple. This creates a grid-like format for data.

It is perfect for representing fixed data sets. Think of a chessboard, coordinate points, or a simple table. The outer tuple holds the rows. Each inner tuple holds the column values.

This guide will show you how to work with them. You will learn creation, access, iteration, and use cases.

What is a Tuple of Tuples?

A tuple is an immutable, ordered collection. A tuple of tuples nests these collections. The structure is rigid and cannot be changed after creation.

This immutability is a key feature. It ensures data integrity. It is a core concept in Python Tuples: Immutable Data Structures Explained.

It is similar to a two-dimensional list. But it cannot be modified. This makes it safe for constant data.

Creating a Tuple of Tuples

You create it by placing tuples inside parentheses, separated by commas. The syntax is simple and readable.


# Creating a tuple of tuples
coordinates = ((1, 2), (3, 4), (5, 6))
print(coordinates)
    

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

You can also create it from existing variables. This uses tuple packing.


# Creating from variables
row1 = ('Alice', 90)
row2 = ('Bob', 85)
gradebook = (row1, row2)
print(gradebook)
    

(('Alice', 90), ('Bob', 85))
    

For more on this technique, see our Python Tuple Packing and Unpacking Guide.

Accessing Elements

You use double indexing to access elements. The first index selects the inner tuple. The second index selects the item inside it.


matrix = (('a', 'b'), ('c', 'd'), ('e', 'f'))

# Access the first inner tuple
print(matrix[0])  # Output: ('a', 'b')

# Access the second element of the first tuple
print(matrix[0][1])  # Output: 'b'

# Access the last element of the last tuple
print(matrix[-1][-1])  # Output: 'f'
    

('a', 'b')
b
f
    

Remember, indexing starts at 0. Negative indices count from the end.

Iterating Over a Tuple of Tuples

Use loops to process all data. A nested for loop is common. The outer loop gets each row (inner tuple). The inner loop gets each value.


# Iterating with nested loops
scores = ((85, 92, 78), (88, 95, 80))

for student_scores in scores:
    print("New student:")
    for score in student_scores:
        print(f"  Score: {score}")
    

New student:
  Score: 85
  Score: 92
  Score: 78
New student:
  Score: 88
  Score: 95
  Score: 80
    

You can also use tuple unpacking in the loop. This is clean for known structures.


# Iterating with unpacking
points = ((1, 2), (3, 4), (5, 6))
for x, y in points:
    print(f"Point at x={x}, y={y}")
    

Point at x=1, y=2
Point at x=3, y=4
Point at x=5, y=6
    

Common Operations

You can perform several operations. These include finding length, checking membership, and concatenation.

Use the built-in len() function to get dimensions.


data = (('a', 1), ('b', 2), ('c', 3))
print(len(data))     # Number of inner tuples: 3
print(len(data[0]))  # Length of first inner tuple: 2
    

3
2
    

Check if an item exists with the in keyword.


matrix = ((1, 2), (3, 4))
print((1, 2) in matrix)  # True
print(5 in matrix)       # False (checks inner tuples, not their items directly)
    

True
False
    

You can join tuples together. Learn more in the Python Tuple Operations and Concatenation Guide.

When to Use a Tuple of Tuples

Use it for data that should never change. This includes configuration data, constants, or lookup tables.

It is more memory-efficient than a list of lists for static data. It provides a performance benefit.

Common use cases are:

  • Coordinate systems (x, y points).
  • Representing game boards (like Tic-Tac-Toe).
  • Storing constant data like country codes.

# Example: RGB color constants
COLORS = (
    (255, 0, 0,   'Red'),
    (0, 255, 0,   'Green'),
    (0, 0, 255,   'Blue')
)
    

Tuple of Tuples vs. List of Lists

The main difference is mutability. A tuple of tuples is immutable. A list of lists can be changed.

Use a tuple of tuples for data safety. Use a list of lists when you need to modify the data.

For a deep dive, read Python Tuple vs List: Key Differences Explained.


# Tuple of Tuples - Immutable
tuple_data = ((1, 2), (3, 4))
# tuple_data[0] = (5, 6)  # This would raise a TypeError

# List of Lists - Mutable
list_data = [[1, 2], [3, 4]]
list_data[0] = [5, 6]  # This is allowed
print(list_data)
    

[[5, 6], [3, 4]]
    

Conclusion

A tuple of tuples is a simple yet powerful tool. It stores multi-dimensional, immutable data efficiently.

You now know how to create, access, and loop through them. You understand their best use cases and advantages.

Remember its key strength: immutability. This guarantees your data remains constant and reliable. Use it for fixed data structures in your programs.