super()何时需要参数才能正常运行?

时间:2018-09-17 03:47:12

标签: python python-3.x

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()形式。任何帮助将不胜感激!

0 个答案:

没有答案