🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 概述 多态 #### 例子 ```python from mod.attrdisplay import AtrrDisplay class Person(AtrrDisplay): def __init__(self, name, job=None, pay=0): self.name = name self.job = job self.pay = pay def lastName(self): return self.name.split()[-1] def giveRaise(self, percent): self.pay = round(self.pay * (1 + percent), 2) class Manager(Person): def __init__(self, name, pay): Person.__init__(self, name, 'mgr', pay) def giveRaise(self, percent, bonus=0.1): Person.giveRaise(self, percent + bonus) if __name__ == '__main__': bob = Person('bob smith') sue = Person('sue jones', 'dev', 10000) tom = Manager('Tom Jones', 50000) for object in (bob, sue, tom): object.giveRaise(0.1) print(object) ``` 在进行输出显示的时候,python会执行相应的giveRaise,bob和sue执行Person类中的方法,tom针对的就是定制的Manager