python_super注意事项

class room:
def __init__(self,area=120,usedfor='sleep'):
self.area = area
self.usedfor = usedfor
def display(self):
print("this is my house")

class babyroom(room):
def __init__(self,area=40,usedfor="son",wallcolor='green'):
super().__init__(area,usedfor)
self.wallcolr = wallcolor
def display(self):
super().display()
print("babyroom area:%s wallcollor:%s"%(self.area,self.wallcolr))

class rent:
def __init__(self,money=1000):
self.rentmoney = money
def display(self):
print("for rent at the price of %s"%self.rentmoney)

class agent(babyroom,rent):
#class agent(rent,babyroom):
def display(self):
   super().display()
print("rent house agent")
agent().dispaly()


output:

  class agent(babyroom,rent)类输出为:
    this is my house
    babyroom area:green wallcollor
    rent house agent
  
class agent(rent,babyroom)类输出:

    for rent at the price of 1000
    rent house agent
 


原文地址:https://www.cnblogs.com/jiejunwang/p/8477458.html