Member-only story
Parents And Children In Python
Inheritance: Extending Classes To Make New Classes
As you might know, creating a fully functional class in an object-oriented programming language is time-consuming because real classes perform a lot of complex tasks.
In Python, you can get the features you want from an existing class(parent) to create a new class(child). This Python feature is called inheritance.
By inheritance, you can
- obtain the features of a parent class,
- change the features that you don’t need,
- add new features to your child class. (derived class or subclass)
Since you are using a pre-used, tested class, you don’t have to put quite as much effort into your new class. The child class inherits the attributes and functions of its parent class.
If we have several similar classes, we can define the common functionalities of them in one class and define child classes of this parent class and implement specific functionalities there.