Single Inheritance
Create child classes that inherit attributes and methods from a parent.
Introduction
Inheritance lets a child class reuse and extend the behavior of a parent class without duplicating code.
Defining a Child Class
class Dog(Animal): inherits everything from Animal. The child class can add new methods or override existing ones.
class Animal:
def __init__(self, name): self.name = name
def speak(self): return '...'
class Dog(Animal):
def speak(self): return 'Woof'
d = Dog('Rex')
print(d.name, d.speak())