我想知道什么时候使用哪个版本的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)
到目前为止,我只使用过没有参数的super()
,它按照我的期望工作(对于Java开发人员来说)。
问题:
- 在这个上下文中,“bound”是什么意思?
- “绑定的(super)对象”和“未绑定的(super)对象”有什么区别?
- 什么时候使用
super(type, obj)
,什么时候使用super(type, type2)
? - 像
Mother.__init__(...)
这样命名超类会更好吗?
B
是一个类名,b = B()
是一个实例,那么B
是一个未绑定的对象,而b
是一个绑定的对象。 - smci