Inheritance
One class taking another's behaviour, overriding part of it, and calling back into the parent with super().
Overview
The basic move
class Dog(Animal):
def speak(self):
return "woof"
Dog gets everything Animal has. Where it defines a method of the same name, that version wins — that is overriding.
The payoff shows up in methods the parent already wrote:
def describe(self):
return f"{self.name} says {self.speak()}"
describe was written once on Animal and calls whichever speak the actual object has. Add a tenth animal and describe needs no change. That is the whole argument for inheritance in one method.
inheritance.py
super_and_mro.py
Worth knowing
class Dog(Animal) gives Dog everything Animal has, before Dog adds anything.super().__init__ should call super().__init__(...) or the parent's setup never runs.