![]() | ![]() |
A way of creating a new class by using details of existing class devoid of modifying it is called inheritance. The derived class or child class is the newly formed class while the existing class is called parent or base class.
Example
Start IDLE.
Navigate to the File menu and click New Window.
Example
Start IDLE.
Navigate to the File menu and click New Window.
Type the following:
Discussion
We created two Python classes in the program above. The classes were Dog as the base class and Pitbull as the derived class. The derived class inherits the functions of the base class. The method _init_() and the function super() are used to pull the content of _init_() method from the base class into the derived class.