In this lesson, you’ll learn about the collections.namedtuple
data structure. namedtuple
is a subclass of tuples and creates tuple-like immutable objects:
>>> from collections import namedtuple
>>> Car = namedtuple("Car", ["color", "make", "model", "mileage"])
>>> my_car = Car(color="midnight silver", make="Tesla", model="Model Y", mileage=5)
>>> my_car.color
'midnight silver'
You can read more about namedtuple
in the documentation for the Python collections module.
James Uejio RP Team on April 27, 2020
Here is the Python documentation on namedtuple: Python collections module