super()
lets you avoid referring to the base class explicitly, which can be nice.
(super()
可以避免显式引用基类,这可能很好。)
But the main advantage comes with multiple inheritance, where all sorts of fun stuff can happen. (但是主要优势来自多重继承,其中可以发生各种有趣的事情。)
See the standard docs on super if you haven't already. (如果还没有的话,请参阅关于super的标准文档 。)
Note that the syntax changed in Python 3.0 : you can just say super().__init__()
instead of super(ChildB, self).__init__()
which IMO is quite a bit nicer.
(请注意, Python 3.0中的语法已更改 :您只能说super().__init__()
而不是super(ChildB, self).__init__()
,这对IMO来说要好得多。)
The standard docs also refer to a guide to using super()
which is quite explanatory. (标准文档还参考了使用super()
的指南,这是非常说明性的。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…