为什么Python3.x的超级()魔法?
super()
class A(object):
def x(self):
print("Hey now")class B(A):
def x(self):
super().x()>>> B().x() Hey now
supersuper_
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
随时随地看视频慕课网APP
相关分类