Glossary

Named Tuple

Also known as: namedtuple

A named tuple is a tuple subclass whose elements can be accessed by name as well as by index. Created with collections.namedtuple('Point', ['x', 'y']) or (more modernly) by subclassing typing.NamedTuple, named tuples combine the immutability and memory efficiency of tuples with the readability of accessing fields by name.

Named tuples are ideal for representing simple records — coordinates, database rows, API responses — where you want structured access without the overhead of defining a full class. They support all tuple operations (unpacking, slicing, iteration) plus named attribute access (point.x), a ._asdict() method for conversion to a dictionary, and a ._replace() method for creating a modified copy.

Since Python 3.6, typing.NamedTuple provides a cleaner class-based syntax with type annotations: class Point(NamedTuple): x: float; y: float. For cases where mutability or more features (default values, comparison, hashing, repr) are needed, dataclasses (Python 3.7+) are the modern alternative. Named tuples remain the best choice when you specifically want immutability, tuple compatibility, and minimal memory overhead.

Related terms: Tuple, Dataclass

Discussed in:

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