继承实现代码重用
class People: school="luffcity" def __init__(self, name, age, sex,): self.name = name self.age = age self.sex = sex class Teacher(People): schoole=‘Luffycity‘ def __init__(self,name,age,sex,level,salary): super(Teacher,self).__init__(name,age,sex) self.level=level self.salary=salary def teach(self): print("%s is teaching" % self.name) class Student(People): schoole = ‘Luffycity‘ def __init__(self, name, age, sex, class_time): super(Student, self).__init__(name, age, sex) self.class_time=class_time def learn(self): print("%s is learning" % self.name) t1=Teacher(‘alex‘,18,‘male‘,10,3000) s1=Student(‘zhangsan‘,28,‘female‘,‘08:30:00‘)
原文地址:https://www.cnblogs.com/yaya625202/p/8870657.html
时间: 2024-11-04 00:49:41