Subclasses

You'll learn about the concept of subclasses in Python in this lesson.

Introduction to subclasses

A class inherits all the instance variables and methods of its superclass. (It is a subclass of its superclass.) For example:

class Friend(Person):
  def smile(self):
    print('¯\_(^-^)_/¯')

meg = Friend('Margaret', 25)

In the above example, when you create meg as an instance of Friend, meg will have the say_hi, get_older, and get_much_older methods of the Person class, along with the smile method and the __init__ constructor. Since ...