May 2017
Intermediate to advanced
280 pages
6h 2m
English
In this section, we will learn about inheritance. Inheritance allows us to inherit methods and attributes of the parent class. By inheritance, a new child class automatically gets all of the methods and attributes of the existing parent class. The syntax is given as follows:
class DerivedClassName(BaseClassName): <statement-1> . . . <statement-N>
If you remember, in Chapter 10, File Handling and Exceptions, we had inherited the built-in class exception. Starting with the existing code, let's make the instructor class, which would inherit the method of the Leapx_org class. Refer to the code in classinheri1.py:
class Leapx_org(): mul_num = 1.20 count= 0 def __init__(self,first,last,pay): self.f_name = first self.l_name ...
Read now
Unlock full access