多态: 对不同类型的对象执行相同的操作
class Dog(object):
def set_name(self,name):
self.name=name
def greet(self):
print("{}: Wang Wang!".format(self.name))
class Human(object):
def set_name(self,name):
self.name=name
def greet(self):
print("{}: Hello, world!".format(self.name))
>>> dog=Dog()
>>> dog.set_name("Old Black")
>>> dog.greet()
Old Black: Wang Wang!
>>> man=Human()
>>> man.set_name("Zhang San")
>>> man.greet()
Zhang San: Hello, world!