1 # -*- coding: utf-8 -*- 2 # @Time : 2018/10/17 11:02 3 # @Author : wangyafeng 4 # @Email : [email protected] 5 # @Software: PyCharm 6 7 8 class Father(object): 9 def __init__(self,color,sport): 10 self.color=color 11 self.sport=sport 12 13 def play(self): 14 return "i lover %s"%self.sport 15 16 17 class Mother(object): 18 def __init__(self,food): 19 self.food=food 20 21 def do(self): 22 return "i lover %s"%self.food 23 24 #方法1 25 # class Son(Father,Mother): 26 # def __init__(self,color,sport,food,stu): 27 # super(Son, self).__init__(color,sport) #注意 28 # super(Father,self).__init__(food) #注意 29 # self.stu=stu 30 31 32 #方法2 33 class Son(Father,Mother): 34 def __init__(self,color,sport,food,stu): 35 Mother.__init__(self,food) 36 Father.__init__(self,color,sport) 37 self.stu=stu 38 39 def mystu(self): 40 return "i love %s"%self.stu 41 42 43 s1=Son("bule","篮球","牛排","化学") 44 print(s1.mystu()) 45 print(s1.play()) 46 print(s1.do())
Python3 带参数的多重继承
猜你喜欢
转载自www.cnblogs.com/wangyafeng/p/9808769.html
今日推荐
周排行