Empty Objects

Learn about empty objects in Python.

In our examples so far, we’ve already seen many of the built-in Python data structures in action. In this chapter, we’ll discuss the object-oriented features of these data structures, when they should be used instead of a regular class, and when they should not be used. In particular, we’ll be covering the following topics:

  • Tuples and named tuples
  • Dataclasses
  • Dictionaries
  • Lists and sets
  • Three types of queues

This chapter’s case study will revisit the data model for the kk-nearest neighbors classifier. After looking at Python’s sophisticated built-in data structure and class definitions, we can simplify some of the application class definitions. We’ll start by looking at some of the foundational constructs. The object class, specifically.

Let’s start with the most basic Python built-in, one that we’ve used implicitly many times already, the one (it turns out) we’ve extended in every class we have created: the object.

Creating an instance

Technically, we can instantiate an object without writing a subclass, as follows:

Get hands-on with 1200+ tech skills courses.