首页 > 解决方案 > super() 接受 2 个相同的类但返回另一个类的方法

问题描述

嗨,我对 Python 的超级函数的语法有一些问题..

class x:
    def __init__(self):
        pass

class p(x):
    def __init__(self):
        print(super(p,self).__init__())

输出:

<bound method x.__init__ of <__main__.y object at 0x000001FF918EC898>>

这是 的__init__方法x。所以问题是,selfp本身在p。我们调用super(p,self),并且通过这种方式我们给p超级函数两次类,但它返回x__init__方法..怎么样?

标签: pythonpython-3.x

解决方案


推荐阅读