💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 概述 多态 #### 例子 ```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