table of Contents
Chapter XI inheritance, class
First, what is inherited
Inheritance is a new class of embodiment , the new class is called the child class , called the class inherited superclass
Inherited properties: subclasses genetic properties and functions of the parent class
Second, why should inherit
- You can reduce redundant code
Third, inherited objects
python class may inherit a plurality of parent classes
class Parent1: pass class Parent2: pass class Son(Parent1, Parent2): pass
print(Sub1.__bases__) ----------------------------------------- #(<class '__main__.Parent1'>, <class '__main__.Parent2'>)
In Python3 If a class does not inherit any class, the default object class inheritance
If a class does not inherit any class in Python2, the object will not inherit the class
print(Parent1.__bases__) (<class 'object'>,)
Fourth, the classification category
The new class
- Inherited class and subclass of the class of object, are the new class
- All classes are Python3 new class
Classic
- Not inherited class and subclass of the class of object, are Classic
- Only Python2 in the only Classic