does Python support multiple inheritance? Python Development Learning
inheritance is an important way of object-oriented programming, and through inheritance, subclasses can extend the functionality of the parent class. Python also has this feature, and in addition, Python can use multiple inheritance.
Grammar:
Class Subclass (BASE1,BASE2)
the meaning of this syntax is to create a Subclass class so that it inherits the same Base1 and the Base2 related attributes, and about inheritance also have a the following rules need to be followed:
1. Inheritance inherits only the methods of the parent class and cannot inherit the variables of the parent class;
2. To inherit the variables of the parent class, you need to execute the __init__ (self) method of the parent class;
3. The variable or method at the beginning of the underscore is considered to be protected and cannot be directly point out, but it can be used if forced to do so, but there is a warning;
4. You cannot use self in a static method, declare it as a static method with @staticmethod.
Instance:
Class A (object):
def __init__ (self):
Print (' A ')
Super (A, self). __init__ ()
Class B (object):
def __init__ (self):
Print (' B ')
Super (B, self). __init__ ()
class C (A, B):
def __init__ (self):
Print (' C ')
Super (C, self). __init__ ()
the above instance is a subclass C multiple inherits the characteristics of A and B, is the most basic usage of multiple inheritance, in addition, there are many uses, the use of multiple inheritance is to be aware of, improper use, it may bring more trouble than solve the problem, so unless the existing code to achieve the desired functionality, it is recommended not to consider using multiple inheritance!
Does Python support multiple inheritance? Python Development Learning