Is there a reason why people use super(class, self).__init__() instead of super().__init__()?

本文探讨了在Python中使用super()函数时,为了兼容Python2.x和Python3.x的不同语法,如何正确地调用super()。在Python2中,需要显式地传递class和self参数,而在Python3中则不需要。即使在不使用Python3的情况下,添加(class, self)也不会破坏代码,确保了代码的跨版本兼容性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值