Tao*_*lam 4 python inheritance class python-3.x
我有代码剪断如下:
class A:
def test(self):
return 'A'
class B(A):
def test(self):
return 'B->' + super(B, self).test()
print(B().test())
Run Code Online (Sandbox Code Playgroud)
输出:B->A
如果我写这样的东西,那么我会得到相同的输出:
class A:
def test(self):
return 'A'
class B(A):
def test(self):
return 'B->' + super().test() # change to super()
print(B().test())
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,我都得到相同的输出。那么,我想知道这两种调用的区别是super什么?使用它们中的任何一个都有什么优点和缺点?