Glossary

Tuple

A tuple is an ordered, immutable sequence type in Python. Tuples are created with parentheses ((1, 2, 3)) or simply with commas (1, 2, 3), and they can hold objects of any type. A single-element tuple requires a trailing comma: (42,). Because tuples are immutable, they have no .append(), .remove(), or .sort() methods.

Tuples serve several distinct roles in Python. First, they are used as records: lightweight containers for a fixed number of fields, such as (latitude, longitude) or (name, age, email). The collections.namedtuple and typing.NamedTuple classes add field names to this pattern. Second, tuples are used wherever immutability is required — as dictionary keys, set elements, or function return values when you want to return multiple items.

Because tuples are immutable, they are hashable (provided all their elements are hashable), slightly more memory-efficient than lists, and marginally faster to create. CPython even caches small tuples as an optimisation. Despite their simplicity, tuples support unpacking (x, y, z = my_tuple), which is central to Pythonic idioms like a, b = b, a for swapping variables and for key, value in d.items() for iterating over dictionaries.

Related terms: Immutable, List, Named Tuple

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.