Object-oriented programming creates reusable patterns of code to prevent code redundancy in projects. One way that recyclable code is created is through inheritance, when one subclass leverages code from another base class.
Inheritance is when a class uses code written within another class.
Classes called child classes or subclasses inherit methods and variables from parent classes or base classes.
Because the Child subclass is inheriting from the Parent base class, the Child class can reuse the code of Parent, allowing the programmer to use fewer lines of code and decrease redundancy.
Derived classes are declared much like their parent class; however, a list of base classes to inherit from is given after the class name −
class SubClassName (ParentClass1[, ParentClass2, …]):
'Optional class documentation string'
class_suite
References: https://www.pythonslearning.com/2020/08/inheritance-in-python-tutorials-point_3.html
Best of luck!!!
Top comments (0)