Login
📚 Introduction to Python Programming
Chapters ▾
⇩ Download ▾

13.2 Attribute access

Learning objectives

By the end of this section you should be able to

  • 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.