EX:
class Parent:
def name(self):
print("This is the parent method name()")
class Child(Parent):
def name(self):
super(Child, self).name()
super().name()
dad = Parent()
son = Child()
dad.name()
son.name()
Output:
This is the parent method name()
This is the parent method name()
This is the parent method name()
我对为什么在两种情况下都能正常工作感到困惑,我想知道何时需要在我的代码中使用super(Child,self).name()形式。任何帮助将不胜感激!