Chapter 8
Python Data Structures
Starting in Chapter 2, we introduced some foundational concepts in class definitions. Chapter 3 and Chapter 6 both built on these foundational definitions to add features to a class.
In many examples, we’ve leveraged the built-in Python data structures. In this chapter, we’ll discuss using these data structures as the basis for class definitions. We’ll touch on when they should be used, and how best to make use of them.
The built-in classes are examples of generic types. When writing type hints, parameters can be used to add details; these help clarify how a generic class will be used in a given code context. Additionally, the built-in classes can also be extended by subclasses, where our application can add features to a built-in class.
This chapter will look at several options for defining classes based on built-in types:
-
A tuple is a container of data items. It’...