Python 学生类与大学生子类:属性、方法及继承示例
class Student: def init(self, school, id_num, gender, birth_date): self.school = school self.id_num = id_num self.gender = gender self.birth_date = birth_date
def set_name(self, name):
self.name = name
def set_score(self, score):
self.score = score
def show(self):
print('姓名:', self.name)
print('学校:', self.school)
print('学号:', self.id_num)
print('性别:', self.gender)
print('出生日期:', self.birth_date)
print('成绩:', self.score)
class Undergraduate(Student): def set_department(self, department): self.department = department
def set_major(self, major):
self.major = major
def show(self):
print('姓名:', self.name)
print('学校:', self.school)
print('学号:', self.id_num)
print('性别:', self.gender)
print('出生日期:', self.birth_date)
print('成绩:', self.score)
print('系别:', self.department)
print('专业:', self.major)
原文地址: https://www.cveoy.top/t/topic/nVAF 著作权归作者所有。请勿转载和采集!