0Pricing
Python Academy · Lesson

NamedTuple Basics

Create lightweight immutable records.

What Is a NamedTuple?

A named tuple is a tuple whose positions also have names. You get the lightweight, immutable nature of a tuple plus readable attribute access. It is perfect for small records.

The Problem with Plain Tuples

Plain tuples are positional, so you must remember what each index means. Code like p[0] and p[1] is easy to get wrong.

point = (1, 2)
print(point[0])  # x?
print(point[1])  # y?

All lessons in this course

  1. The Enum Class
  2. IntEnum and Flag
  3. NamedTuple Basics
  4. typing.NamedTuple
← Back to Python Academy