August 2019
Beginner
482 pages
12h 56m
English
The namedtuple collection makes it convenient to store data in an expressive way. You can think of them as a hybrid of tuples and dictionaries, as they get the small memory footprint and immutability from the former and keyword access from the latter. They are very effective if you work with multiple data points of the same structure that have no bound logic, for example, users or goods in the eShop. Before we actually create an instance, we'll have to specify the properties of our future record (immutability, remember?). In the following code snippet, we create a data structure for users that contains the name, surname, and age properties. Once a named tuple is defined, there is no way to change it:
from collections import namedtuple ...
Read now
Unlock full access