为什么Python3.x的超级()魔法?
super()
class A(object): def x(self): print("Hey now")class B(A): def x(self): super().x()
>>> B().x() Hey now
super
super_
super_ = superclass A(object): def x(self): print("No flipping")class B(A): def x(self): super_().x()
>>> B().x() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in x RuntimeError: super(): __class__ cell not found
super()
慕勒3428872
相关分类