多态:一种接口,多种实现
python没有直接可以实现多态的语法,但是可以实现多态。
# __*__ coding: utf-8 __*__# __author__ = "David.z"class Animal:def __init__(self,name): self.name = namedef talk(self):pass# raise NotImplementedError("Subclass must implement abstract method")class Cat(Animal):def talk(self):return "Meow"class Dog(Animal):def talk(self):return "Woof! Woof!"animals = [Cat("张三"), Dog("李四")]for animal in animals:print (animal.name + ':'+ animal.talk())