Tuples look and behave like lists for reading — indexing, slicing, iteration, containment checks — but they can never be modified after creation: no append, no item assignment. That immutability makes them hashable, when their contents are also hashable, so they can be used as dictionary keys or set elements, and it also signals to readers that the collection represents a fixed, related group of values, like a coordinate pair or a database row.
1Understanding Tuples
Tuples look and behave like lists for reading — indexing, slicing, iteration, containment checks — but they can never be modified after creation: no append, no item assignment. That immutability makes them hashable, when their contents are also hashable, so they can be used as dictionary keys or set elements, and it also signals to readers that the collection represents a fixed, related group of values, like a coordinate pair or a database row.
Tuple unpacking (x, y = point) is one of Python's most useful idioms — it works for function return values, swapping variables, and iterating over pairs from zip() or dict.items().
point = (3, 4)
x, y = point
print(x, y)2Practical Example
Here is a real-world application of Tuples showing how it is used in production Python code.
def min_max(numbers):
return min(numbers), max(numbers)
lo, hi = min_max([4, 1, 9, 2])
print(lo, hi)3Best Practices
Follow these guidelines when working with Tuples:
1. Use a tuple to return multiple values from a function instead of a custom container class
2. Prefer tuple unpacking over indexing when consuming a fixed-size tuple, for readability
3. Use collections.namedtuple when a tuple's fields need descriptive names instead of positional meaning
Tip: Tuple unpacking (x, y = point) is one of Python's most useful idioms — it works for function return values, swapping variables, and iterating over pairs from zip() or dict.items().
point = (3, 4)
x, y = point
print(x, y)