# 当要使用连个类中的方法和属性有相同的时候,可以只定义一个工具类, # 不同的类,做相同的调用,产生不同的结果 class duck(object): def __init__(self): self.name = 'duck' def step(self): print('duck step') class bird(object): def __init__(self): self.name = 'bird' def step(self): print('bird step') class func(object): def fun(self, obj): print(obj.name) obj.step() one = duck() two = bird() f = func() f.fun(one) f.fun(two)
python多态
最新推荐文章于 2022-11-25 14:41:47 发布