Data Structures
Python’s data structures are deeply unified. Once you understand the protocols that built-in types implement — and the special methods you can implement to participate in those protocols — every other layer of the language clicks into place.
This part walks the ladder:
13 The Python Data Model introduces the data model itself: what dunder methods are, why they exist, and how implementing two of them on a custom class can make it iterate, slice, and sort like a built-in.
14 An Array of Sequences classifies sequences into container vs. flat, mutable vs. immutable, and shows how comprehensions, generator expressions, slicing, and unpacking are all consequences of the same protocol.
15 Dictionaries and Sets explains why dictionaries are the engine of Python — the namespace, the module system, and the class system all rest on them — and what their hash-based design implies for performance.
16 Unicode Text Versus Bytes disentangles
str,bytes, andbytearray, and gives you a working model of Unicode normalization.17 Data Class Builders surveys the four ways Python builds records:
namedtuple,typing.NamedTuple,dataclass, and plain classes — and when to choose each.18 Object References, Mutability, and Recycling fixes the three ideas every Python programmer eventually trips over: variables are labels, not boxes;
==andisask different questions; and==does not survive a copy by default.
By the end of this part, the data model is a tool you reach for, not a curiosity.