Python super() 函数
使用 super() 函数
Python 也有一个 super()
函数,该函数会让子类继承其父类的所有方法和属性:
实例
class Student(Person): def __init__(self, fname, lname): super().__init__(fname, lname)
通过使用 super()
函数,您不必使用父元素的名称,它将自动从父类继承方法和属性。
Python 也有一个 super()
函数,该函数会让子类继承其父类的所有方法和属性:
class Student(Person): def __init__(self, fname, lname): super().__init__(fname, lname)
通过使用 super()
函数,您不必使用父元素的名称,它将自动从父类继承方法和属性。