The initialization method of a class in Python is __init__ (), so the initialization method of the parent class and subclass is this, and if the subclass does not implement __init__ (), the initialization function of the parent class is called,
If the subclass implements this function, the __init__ () of the parent class is called explicitly in this function, which is not the same as C++,java, which automatically calls the parent class constructor.
# example of calling a parent class initialization method in initialization # B is a subclass of a class B (A): def __init__ (self): super (). __init__ ()
Three ways to call other member functions of the parent class:
1. Direct write class name call;
2. Call with super (type, obj) method (ARG).
3. Within the definition of a subclass, if you call a member of the parent class, you can use Super (). Method (Arg) directly.
class A: def method (self, arg): return class B (A): def method (self, arg): # A.method (self,arg) #1 # super (B, Self). Method (ARG) #2 # Super (). Method (ARG) #3
[note] If you are outside the subclass definition (that is, within other function logic, when the subclass object calls the parent class member), follow:
... = B () super (B,ob). Method (ARG) # calls the method of the parent class A of class B. ...
python--some descriptions of the parent class and the child class