Python 3 内置函数 - super()函数 0. super()`函数
1. 使用方法
- 用于调用父类的一个方法 。
super()是用来解决多重继承问题的 。
>>> super?# output:Init signature: super(self, /, *args, **kwargs)## 使用说明Docstring:super() -> same as super(__class__, )super(type) -> unbound super objectsuper(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):@classmethoddef cmeth(cls, arg):super().cmeth(arg)Type:typeSubclasses: 2. 使用示例 【Python 3 内置函数 - `super`函数】# 定义一个base类. 有一个计算平方的方法 。>>> class base:>>>def square(self, x):>>>print("square (base):", x*x)# 定义一个类A. 有两个方法 。>>> class classA(Base):>>>def square(self, x):>>>super().square(x)>>>def add_one(self, x):>>>print(x+1)# 生成实例>>> a = classA()>>> a.square(3)# output:square (base): 9
- 春季老年人吃什么养肝?土豆、米饭换着吃
- 三八妇女节节日祝福分享 三八妇女节节日语录
- 老人谨慎!选好你的“第三只脚”
- 校方进行了深刻的反思 青岛一大学生坠亡校方整改校规
- 脸皮厚的人长寿!有这特征的老人最长寿
- 长寿秘诀:记住这10大妙招 100%增寿
- 春季老年人心血管病高发 3条保命要诀
- 眼睛花不花要看四十八 老年人怎样延缓老花眼
- 香槟然能防治老年痴呆症? 一天三杯它人到90不痴呆
- 老人手抖的原因 为什么老人手会抖
