12.18. OOP Inheritance About

  • Used to avoid code duplication

parent
superclass
base class

Class from other classes inherits

child
subclass

Class which inherits from parent

inherit
derive

Class takes attributes and methods from parent.

12.18.1. One Child

>>> class Parent:
...     pass
>>>
>>>
>>> class Child(Parent):
...     pass

12.18.2. Many Children

>>> class Person:
...     pass
>>>
>>>
>>> class Astronaut(Person):
...     pass
>>>
>>> class Cosmonaut(Person):
...     pass

12.18.3. Use Case - 0x01

>>> class Iris:
...     pass
>>>
>>>
>>> class Setosa(Iris):
...     pass
>>>
>>> class Versicolor(Iris):
...     pass
>>>
>>> class Virginica(Iris):
...     pass