Skip to content

named tuple

In Python, a named tuple is a variation of the built-in tuple data type that allows you to create tuple-like objects with items that have descriptive names. You can access each item by its name using dot notation.

Named tuples are available through the collections module (namedtuple) and the typing module (NamedTuple). The typing.NamedTuple class-based syntax is the modern alternative, offering inline type annotations and the ability to add methods and docstrings.

Named tuples are immutable, just like regular tuples, which means that once you create a named tuple, you can’t change its values.

Example

Here’s a quick example of how to use named tuples in Python:

Python
>>> from collections import namedtuple
>>> Point = namedtuple("Point", ["x", "y"])
>>> point = Point(11, 22)
>>> point.x
11
>>> point.y
22

In this example, Point is a named tuple with two fields, .x and .y. You can create an instance of Point by providing values for these fields. Then, you can access those items using dot notation, which makes the code more readable.

Using the modern typing.NamedTuple syntax:

Python
>>> from typing import NamedTuple

>>> class Point(NamedTuple):
...     x: float
...     y: float
...

>>> point = Point(11, 22)
>>> point.x
11

Tutorial

Write Pythonic and Clean Code With namedtuple

Discover how Python's namedtuple lets you create simple, readable data structures with named fields you can access using dot notation.

intermediate data-structures python stdlib

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated March 10, 2026 • Reviewed by Dan Bader