classFather():def__init__(self,Height,Weight):
self.Height = Height
self.Weight = Weight
defPlayGames(self,GameName):print("Father is playing %s"%GameName)deffunc(self):print("Father Func")
创建父类:Mother
classMother():def__init__(self,FaceValue):
self.FaceValue = FaceValue
defEatFood(self,FoodName):print("Mother is eating %s"%FoodName)deffunc(self):print("Mother Func")
创建子类:Child
from Father import Father
from Mother import Mother
classChild(Mother,Father):def__init__(self,Weight,Height,FaceValue):
Father.__init__(self,Weight,Height)
Mother.__init__(self,FaceValue)
子类Child多继承
from Child import Child
defmain():
ChildObj = Child(180,90,100)print("ChildObj.Weight = %d , ChildObj.Height = %d , ChildObj.FaceValue = %d"%(ChildObj.Weight,ChildObj.Height,ChildObj.FaceValue))
ChildObj.PlayGames("HunDouLuo")
ChildObj.EatFood("Noddles")# 继承父类中的同名方法时,首先调用的是子类名称括号后面的第一个父类中的方法
ChildObj.func()if __name__ =='__main__':
main()>>>ChildObj.Weight =90, ChildObj.Height =180, ChildObj.FaceValue =100>>>Father is playing HunDouLuo
>>>Mother is eating Noddles
>>>Mother Func