July 2023
Beginner to intermediate
448 pages
10h 57m
English
So far in this tutorial, we’ve seen many examples of Python objects. In this chapter, we’ll learn how to use Python classes to make objects of our own, which have both data (attributes) and functions (methods) attached to them. We’ll also learn how to define a custom iterator for our class. Finally, we’ll learn how to reuse functionality with inheritance.
Classes are a way of organizing data and functions into a single convenient object. In Python, we can create a class of our own using two basic elements:
Use the class keyword to define the class.
Use the special __init__ method (often called an initializer function) to specify how to initialize a class.
Our concrete example will be a
Read now
Unlock full access