2条回答 默认 最新
- CSDN专家-黄老师 2021-11-01 10:22关注
class person: def __init__(self, mz, nl, xb): self.mz = mz if 0 < nl < 99: self.nl = nl else: print("年龄超出范围", nl) if "男" in xb or "女" in xb: self.xb = xb else: print("性别超出范围:", xb) class student(person): def __init__(self, mz, nl, xb, xh, xx): super().__init__(mz, nl, xb) self.xh = xh self.xx = xx class highStudent(student): def __init__(self, mz, nl, xb, xh, xx, by): super().__init__(mz, nl, xb, xh, xx) self.gh = by self.gz = by class universityStudent(student): def __init__(self, mz, nl, xb, xh, xx, zy, gz): super().__init__(mz, nl, xb, xh, xx) self.zy = zy self.gz = gz class graduateStudent(student): def __init__(self, mz, nl, xb, xh, xx, fx, gz): super().__init__(mz, nl, xb, xh, xx) self.fx = fx self.gz = gz class worker(person): def __init__(self, mz, nl, xb, gh, gz): super().__init__(mz, nl, xb) self.gh = gh self.gz = gz class software(worker): def __init__(self, mz, nl, xb, gh, gz, ji, xx): super().__init__(mz, nl, xb, gh, gz) self.ji = ji self.xx = xx g = graduateStudent('aaa', 90, "男", "007", "python", "python", 600) print(f'mz:{g.mz}, nl:{g.nl}: xb:{g.xb}, xh"{g.xh}, xx:{g.xx}, fx"{g.fx},gz:{g.gz}')
类的实例化你按照上面的实例化其他就行了
如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报