Implement a subclass that accesses inherited attributes from the superclass.
Write a subclass's __init__ that inherits superclass instance attributes and creates new instance attributes.
Creating a simple subclass
Subclasses have access to the attributes inherited from the superclass. When the subclass's __init__ isn't explicitly defined, the superclass's __init__ method is called. Accessing both types of attributes uses the same syntax.
Using __init__ to create and inherit instance attributes
A programmer often wants a subclass to have new instance attributes as well as those inherited from the superclass. Explicitly defining a subclass's __init__ involves defining instance attributes and assigning instance attributes inherited from the superclass.
Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.
These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.