求助大神 最近在用python搭建网站模块出错

2024-12-30 03:59:28
推荐回答(1个)
回答1:

#_*_encoding:utf-8_*_ class people: #定义基本属性 name = '' age = 0 #定义私属性私属性类外部直接访问 __weight = 0 #定义构造 def __init__(self,a,w):#调用需传入self相于this self.name = 'MHC' self.age = a self.weight = w def speak(self): print "%s is speaking: I am %d years old."%(self.name,self.age) p = people(10,30) p.speak() class student(people): grade = 0 def __init__(self,a,w,g): #调用父类构造函数 people.__init__(self,a,w) self.grade = g #覆写父类speak def speak(self): print "%s is speaking: I'am %d years,and I'm in grade %s "%(self.nameself.age,self.grade) s = student(100,60,3,100) s.speak(