Python super() 函数
实例
创建一个将从另一个类继承所有方法和属性的类:
class Parent:def __init__(self, txt):self.message = txtdef printmessage(self):print(self.message)class Child(Parent):def __init__(self, txt):super().__init__(txt)x = Child("Hello, and welcome!")x.printmessage()
定义和用法
super() 函数用于提供对父类或同胞类的方法和属性的访问。
super() 函数返回代表父类的对象。
语法
super()
参数值
无参数