Python基础之面向对象三大特征 -多态 基于鸭子类型的多态# 定义类classDog:defgo(self):print(小狗熊)# 定义类classFish:defgo(self):print(鱼儿游)# 定义类classBird:defgo(self):print(鸟儿飞)# 定义类classRobot:defgo(self):print(机器人走路)# 定义函数defgo(things):things.go()# 测试 在运行时根据传入的对象不同自动绑定这个对象所对应类型的go方法go(Dog())go(Bird())go(Fish())go(Robot)

本月热点