class A: def my_method(self): print("A method called") class E: def my_method(self): print("E method called") class D(E): def my_method(self): print("D method called") class B(D): def my_method(self): print("B method called") class C(A, B): def my_method(self): # super().my_method() #A method called super(C, self).my_method() #A method called 找C的父类A super(D, self).my_method() #E method called 找D的父类E super(A, self).my_method() #B method called 找A的父类没有,所以找C的下一个B # print("C method called") obj = C() obj.my_method()
python super函数调用父类函数用法
于 2023-09-12 13:50:01 首次发布