gpt4 book ai didi

python - [ python ] : confused by super()

转载 作者:太空狗 更新时间:2023-10-30 02:49:39 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Understanding Python super()

B 是类 A 的子类,所以在 B 的 __init__ 中我们应该像这样调用 A 的 __init__ :

class B(A):
def __init__(self):
A.__init__(self)

但是对于 super(),我看到了这样的东西:

class B(A):
def __init__(self):
super(B, self).__init__() #or super().__init__()

我的问题是:

  1. 为什么不是 super(B, self).__init__(self)?仅仅因为返回的代理对象是绑定(bind)的?

  2. 如果我省略了 super 中的第二个参数并且返回的代理对象是一个未绑定(bind)的对象,那么我应该写成 super(B).__init__(self) 吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com