super() : 获取当前类的父类
效果图:
代码:
class Animal: def __init__(self,name): self._name = name @property def name(self): return self._name @name.setter def name(self,name): self._name = name class Dog(Animal): def __init__(self,name,age): # super()获取当前类的父类 # 并且通过super()返回对象调用父类方法时,不需要传递self super().__init__(name) # 替换这个 self._name = name self._age = age @property def age(self): return self._age @age.setter def age(self,age): self._age = name d = Dog('001',19) print(d.name) print(d.age)