liveBook · Manning

Named tuple

A named tuple is a tuple-like record whose fields are accessible by descriptive names as well as positional indexes.

How 3 Manning books explain it

Python How-To

A named tuple is an immutable tuple-like data structure whose elements can be accessed by descriptive field names as well as by position.

How it is used
Provides a lightweight, mostly read-only model for task data without writing a custom class.
How deep it goes
Works through creation, named-field access, and record parsing; raises updating an immutable instance as a challenge.
Examples
Uses task records with title, description, and urgency, plus latitude-and-longitude return values.
What you can do after
Build it from scratch with collections.namedtuple and use named fields to read parsed task records.

Read how Python How-To explains named tuple →

Tiny Python Projects: Learn coding and testing with puzzles and games

A typed named tuple is an immutable tuple-like record whose fields have names and declared types.

How it is used
Models explicit, carefully controlled program state in an interactive Tic-Tac-Toe game.
How deep it goes
Defines construction, indexing, named access, immutability, typed fields, defaults, and _replace(), but not implementation internals.
Examples
Uses cell-and-player records, a full Tic-Tac-Toe state, default initialization, invalid fields, and immutable turn updates.
What you can do after
Apply typed named tuples to represent state, update them with _replace(), and check type misuse with mypy.

Read how Tiny Python Projects: Learn coding and testing with puzzles and games explains named tuple →

.NET in Action, Second Edition

A named tuple is a C# tuple whose elements have programmer-defined names in addition to positional access.

How it is used
Carries font names alongside FiggleFont objects for filtering and sorting an HTTP response.
How deep it goes
Defines named and unnamed tuple elements and shows a typed LINQ projection, without exploring tuple internals.
Examples
Uses an AllFonts collection pairing reflected property names with FiggleFont objects.
What you can do after
Apply it via C# named tuples to carry related values through a LINQ query without declaring a new type.

Read how .NET in Action, Second Edition explains named tuple →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.