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
- The Enum Class
- IntEnum and Flag
- NamedTuple Basics
- typing.NamedTuple