首页 > 解决方案 > super() 什么时候需要参数才能正常工作?

问题描述

前任:

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() 形式。任何帮助是极大的赞赏!

标签: pythonpython-3.x

解决方案


推荐阅读