Python/ref func super
来自菜鸟教程
<languages />
Python super()函数
例
创建一个将从其他类继承所有方法和属性的类:
class Parent:
def __init__(self, txt):
self.message = txt
def printmessage(self):
print(self.message)
class Child(Parent):
def __init__(self,
txt):
super().__init__(txt)
x = Child("Hello,
and welcome!")
x.printmessage()
定义和用法
The
super()
函数用于提供对父类或兄弟类的方法和属性的访问。
The
super()
函数返回一个代表父类的对象。
句法
super()
参数值
没有参数