May 2017
Intermediate to advanced
280 pages
6h 2m
English
In multiple inheritance, a class inherits the attributes and methods from more than one parent class. Let's take a simple example classmultiple.py:
class A(): def sum1(self,a,b): c = a+b return cclass B(): def sub1(self,a,b): c = a-b return cclass C(A,B): passc_obj = C()print "Sum is ", c_obj.sum1(12,4)print "After substraction ",c_obj.sub1(45,5)
In the preceding code, we have created three classes. Class A contains a sum1() method, which performs the sum of two numbers. Class B contains a sub1() method, which performs the subtraction of two numbers. Class C is the class that inherits classes A and B. The c_obj instance is an instance of class C. The statement c_obj.sum1(12,4) calls the sum1() method of class A. The ...
Read now
Unlock full access