1 class people(): 2 def __init__(self,name): 3 self.name = name 4 self.age = ‘21‘ 5 6 def sit(self): 7 print(‘%s坐下‘ % self.name) 8 9 def say(self): 10 print(‘%s说话‘ % self.name) 11 12 def edit_age(self,age): 13 self.age = age 14 15 jack = people(‘jack‘) 16 jack.sit() 17 jack.say() 18 jack.age = 5 19 print(jack.age) 20 jack.edit_age(30) 21 print(jack.age) 22 23 class son(people): 24 def __init__(self,name,sex,*age): 25 super().__init__(name,*age) 26 self.sex = sex 27 28 def eat(self): 29 print(‘%s在吃‘ % self.sex) 30 # 重写父类 31 def say(self): 32 print(‘%s在说话,是个%s的‘ % (self.name,self.sex)) 33 34 shabi = son(‘dada‘,‘男‘) 35 shabi.edit_age(100) 36 print(shabi.age) 37 shabi.eat() 38 shabi.say()