September 2026
1051 pages
35h 4m
English
Many functions in the standard library return their result as a named tuple. This is a tuple for which each of its fields has a name. The values of the tuple can be accessed via the field names, which is why named tuples lead to more readable code. An example of a named tuple is version_info in the sys module of the standard library, which specifies the version of the Python interpreter:
>>> import sys>>> sys.version_infosys.version_info(major=3, minor=11, micro=0, releaselevel='candidate', serial=1)
The fields of a named tuple can be accessed like attributes:
>>> sys.version_info.major3
A named tuple can be created using the namedtuple function of the collections module.
Read now
Unlock full access