Python 我们是否应该;超级();在底层?
在Python 3中,我使用继承类中的super,如下所示:Python 我们是否应该;超级();在底层?,python,python-3.x,super,method-resolution-order,Python,Python 3.x,Super,Method Resolution Order,在Python 3中,我使用继承类中的super,如下所示: class Orange(Fruit): def __init__(self): super().__init__() 在上面的代码片段中,Orange类继承自Fruit类。看看父类 class Fruit(): def __init__(self): pass # call super().__init__() here? 我们是否需要从父类/基类调用super才能使M
class Orange(Fruit):
def __init__(self):
super().__init__()
在上面的代码片段中,Orange
类继承自Fruit
类。看看父类
class Fruit():
def __init__(self):
pass # call super().__init__() here?
我们是否需要从父类/基类调用super才能使MRO有效工作?否,在Python中,对基类调用
super
上的\uuu init\uuu
没有意义,除非使用多重继承,否则MRO仍将正确初始化。