python 面向对象 (多态)

什么是多态?多态就像是人有多种心情,场景不一样心情就会不一样.

 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 哈士奇

 

posted @ 2018-08-03 10:11  razryang  阅读(131)  评论(0编辑  收藏  举报