The ABCs of abstract base classes

In Chapter 6, More Complex Data Types, we looked at the collections module, which offers a number of variations on the mapping theme. These different kinds of collections are built on a foundation of abstract base classes, defined in the collections.abc module. Looking at this module exposes the common features, and the differences, among the collections.

We can see how Sequence is the basis for the built-in tuple class, and MutableSequence is the basis for the built-in list. The Set abstract base class is the basis for the frozenset built-in class, and MutableSet is the basis for the set class. There's no concrete implementation of the Mapping class, but the dict class is the built-in implementation of the MutableMapping ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.