什么是多态?多态就像是人有多种心情,场景不一样心情就会不一样.
1 class Dog: 2 def print_self(self): 3 print('this is dog') 4 class Hsq(Dog): 5 def print_self(self): 6 print('this is 哈士奇') 7 def introduce(temp): 8 temp.print_self() 9 dog1 = Dog() 10 dog2 = Hsq() 11 introduce(dog1) 12 introduce(dog2)
--->
this is dog
this is 哈士奇