继承实例讲解>>>alex onceagain

描述一个学校,讲师,学员的3个类(对应kc86)

class School(
    object):  # 以后写类都是用新式类,虽然py3里面都是按照广度优先。说不定以后就必须要加Object,基类,所有类的类。以后如果要在面向对象里面加点东西,就需要在基类里面加就行了
    def __init__(self, name, addr):
        self.name = name
        self.addr = addr
        self.students = []
        self.teachers = []

    def enroll(self, stu_obj):  # stu_obj学生实例

        print("为学员%s 办理注册手续" % stu_obj.name)
        self.students.append(stu_obj)


class SchoolMember(object):
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex

    def tell(self):
        pass


class Teacher(SchoolMember):
    def __init__(self, name, age, sex, salary, course):
        super(Teacher, self).__init__(name, age, sex)
        self.salary = salary
        self.course = course

    def tell(self):
        print("""
        ---- info of Teacher : {} ----
        
上一篇:面向对象介绍>>>实例变量和类变量(再一次了解)__alex


下一篇:int、bool、str