Python supports the object-oriented programming style. Here we mainly talk about multiple inheritance in python:
The following code uses python2.4 and the idle IDE development environment after installation (IDE is much simpler than delphi and VS.net)
Create a. py File from the File-New menu and write down the following code:
Class SuperClass:
Def sample (self ):
Print 'superclass'
Class SubClass (SuperClass ):
Pass
Sub = SubClass ()
Sub. sample ()
Save the file and press F5 to display it in the main idle window:
>>>================================== RESTART ==== ======================================
>>>
SuperClass
>>>
The subclass calls the sample method of the parent class. The code is modified as follows:
Class SuperClass:
Def sample (self ):
Print 'superclass'
Class SuperClass1:
Def sample (self ):
Print 'superclass1'
Class SubClass (SuperClass, SuperClass1 ):
Pass
Sub = SubClass ()
Sub. sample ()
Run the code and the result is the same as the above. Here, the subclass calls the sample method of the first parent class, and the second parent class is not called,
Now you know what to say. Change the declaration of the SubClass class:
Class SubClass (SuperClass1, SuperClass ):
Pass
Run. The result is that the SuperClass1 sample method is called.
>>>================================== RESTART ==== ======================================
>>>
SuperClass1
>>>
Here, we can see that when multiple inheritance occurs, the same method in the parent class calls the method of the first parent class declared by the class in the subclass.