相关疑难解决方法(0)

在Python 3中调用super()的4种方法中的哪一种?

我想知道什么时候使用Python 3 super()的味道.

Help on class super in module builtins:

class super(object)
 |  super() -> same as super(__class__, <first argument>)
 |  super(type) -> unbound super object
 |  super(type, obj) -> bound super object; requires isinstance(obj, type)
 |  super(type, type2) -> bound super object; requires issubclass(type2, type)
Run Code Online (Sandbox Code Playgroud)

到目前为止,我super()只使用了没有参数,它按预期工作(由Java开发人员).

问题:

  • 在这种情况下,"约束"意味着什么?
  • 绑定和未绑定的超级对象有什么区别?
  • 何时使用super(type, obj)和何时super(type, type2)
  • 如此命名超级类会更好Mother.__init__(...)吗?

python oop super python-3.x

20
推荐指数
2
解决办法
8109
查看次数

如何在python中使用带有一个参数的super()

在阅读Python中的super()对象时,我阅读了以下语句:

如果省略第二个参数,则返回的超级对象是未绑定的

这究竟是什么意思,我如何super()在代码中使用一个参数?

python super

20
推荐指数
1
解决办法
975
查看次数

标签 统计

python ×2

super ×2

oop ×1

python-3.x ×1