首页 > 其他 > 详细

super多继承

时间:2019-07-31 21:04:24      阅读:150      评论:0      收藏:0      [点我收藏+]
 1 class Father():
 2     def __init__(self, name, house):
 3         self.name = name
 4         self.house = house
 5     def work(self):
 6         print("挣钱养家")
 7     def eat(self):
 8         print("Father -- 吃饭")
 9 class Mother():
10     def __init__(self, name, face):
11         self.name = name
12         self.face = face
13     def shopping(self):
14         print("貌美如花")
15     def eat(self):
16         print("Mother -- 吃饭")
17 
18 # 多继承   son -> mother -> father
19 class Son(Mother, Father):
20     def __init__(self, house, name, face, toy):
21         self.toy = toy
22         # Mother.__init__(self, name, face)
23         # Father.__init__(self, name, house)
24         super(Son, self).__init__(name, face)   # Mother
25         super(Mother, self).__init__(name, house)   # Father
26 
27 
28     def eat(self):
29         # Mother.eat(self)
30         # Father.eat(self)
31         print("son -- eat")
32 
33 son1 = Son("h", "N", "F", "T")
34 print(son1.toy)
35 print(son1.name)
36 print(son1.face)
37 print(son1.house)

 

super多继承

原文:https://www.cnblogs.com/BKY88888888/p/11278788.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!