I suppose people use it to make the code compatible with Python2.x.
Otherwise all Python2 users would have to add the class and self to the super call.
I’m not using Python3, but I think it doesn’t break the code to add (class, self).
Is there a reason why people use super(class, self).__init__() instead of super().__init__()?
最新推荐文章于 2021-07-16 11:14:48 发布
本文探讨了在Python中使用super()函数时,为了兼容Python2.x和Python3.x的不同语法,如何正确地调用super()。在Python2中,需要显式地传递class和self参数,而在Python3中则不需要。即使在不使用Python3的情况下,添加(class, self)也不会破坏代码,确保了代码的跨版本兼容性。
2510

被折叠的 条评论
为什么被折叠?



