liveBook · Manning

Named tuple

Also called namedtuple

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
Uses named tuples as lightweight, mostly read-only models for structured application data.
How deep it goes
Explains creation, field access, parsing, alternatives, and immutability, with challenges on updates and serialization.
Examples
Builds task records from delimited strings and proposes grouping latitude and longitude as one return value.
What you can do after
Apply it via Python’s collections.namedtuple to create and access lightweight 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 →

Also covered in

What to know first

Related concepts

Questions about named tuple

What is named tuple?

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

Which Manning books explain named tuple?

Python How-To, Tiny Python Projects: Learn coding and testing with puzzles and games and .NET in Action, Second Edition.

What should I know before learning named tuple?

Manning books that teach named tuple usually introduce tuple, function, key and class first.

What kinds of named tuple are there?

Kinds of named tuple include state.

What is named tuple a kind of?

Named tuple is a kind of tuple. A tuple is a finite, ordered collection of values grouped as a single composite value, often with elements of different types.

What is named tuple part of?

Named tuple is part of collections module. The collections module is a Python standard-library module providing specialized container data types and related utilities.

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.