赞
踩
目录
了解 super() 函数之前,我们首先要知道 super() 的用途是啥?
语法格式:
super([type[, object-or-type]])
函数描述:
参数说明:
返回值:
help 帮助信息:
- >>> help(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)
- | Typical use to call a cooperative superclass method:
- | class C(B):
- | def meth(self, arg):
- | super().meth(arg)
- | This works for class methods too:
- | class C(B):
- | @classmethod
- | def cmeth(cls, arg):
- | super().cmeth(arg)
-
- ... ...

首先我们看一个最基本的子类调用父类方法的示例:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。