devnotes.

Tuples and Immutability

A tuple is an ordered sequence like a list, but immutable once created — its size and contents can never change.

point = (3, 4)
coordinates = 3, 4, 5           # parentheses are optional for tuple literals
single = (5,)                    # a trailing comma is required for a 1-element tuple

# point[0] = 10   # ❌ TypeError — tuples can't be modified

x, y = point                      # unpacking — assigns x=3, y=4
print(f"x={x}, y={y}")

def get_min_max(numbers):
    return min(numbers), max(numbers)   # returning multiple values as a tuple

low, high = get_min_max([5, 2, 8, 1])   # unpacked directly at the call site

Because tuples are immutable, they're hashable (as long as their contents are also hashable) and can be used as dictionary keys or set elements — something lists, being mutable, can never do. This immutability also signals intent: using a tuple communicates "this collection of values shouldn't change," which is useful for representing fixed structures like coordinates, RGB colors, or database rows.

Returning multiple values from a function, as with get_min_max above, is one of the most common uses of tuples in everyday Python — the function actually returns a single tuple, and the caller unpacks it into separate names in one line, a pattern used constantly throughout idiomatic Python code.

Python Tuples and Immutability | DevNotes