什么是多态?多态就像是人有多种心情,场景不一样心情就会不一样.
class Dog:
def print_self(self):
print('this is dog')
class Hsq(Dog):
def print_self(self):
print('this is 哈士奇')
def introduce(temp):
temp.print_self()
dog1 = Dog()
dog2 = Hsq()
introduce(dog1)
introduce(dog2) --->
this is dog
this is 哈士奇