小编Cal*_*sto的帖子

Python的super()如何与多重继承一起工作?

我是Python面向对象编程的新手,我很难理解super()函数(新样式类),尤其是涉及多重继承时.

例如,如果你有类似的东西:

class First(object):
    def __init__(self):
        print "first"

class Second(object):
    def __init__(self):
        print "second"

class Third(First, Second):
    def __init__(self):
        super(Third, self).__init__()
        print "that's it"
Run Code Online (Sandbox Code Playgroud)

我没有得到的是:Third()该类是否会继承构造函数方法?如果是,那么将使用super()运行哪一个?为什么?

如果你想运行另一个怎么办?我知道它与Python方法解析顺序(MRO)有关.

python multiple-inheritance

825
推荐指数
14
解决办法
30万
查看次数

标签 统计

multiple-inheritance ×1

python ×1