• 几处费解的知识点


    class School(object):
    def __init__(self,name,address):#创建类后初始化,self的出现就把后边的name和address包含在肚子里,所以在这个程序中只要被使用就包含name和address功能
    self.name = name
    self.address = address
    self.teacher = []
    self.student = []
    def enroll(self,stu_obj): #出现self则说明后边的stu_obj就可以直接使用stu_obj.name
    self.student.append(stu_obj)
    print("%s 注册学籍" %stu_obj.name)
    def hire(self,tea_obj): #出现self则说明后边的stu_obj就可以直接使用tea_obj.name 还有就是tea_obj是在self肚子中已有功能的添加
    self.teacher.append(tea_obj)
    print("%s 被雇佣" % tea_obj.name)
    class Schoolmates(object):
    def __init__(self,name,age,sex):
    self.name = name
    self.age = age
    self.sex = sex

    class Teacher(Schoolmates):
    def __init__(self,name,age,sex,gongzi,kecheng):
    Schoolmates.__init__(self,name,age,sex)
    self.gongzi = gongzi
    self.kecheng = kecheng
    def teach(self):
    print("%s is teaching %s" %(self.name,self.kecheng))
    def tell(self):
    print('''----- info teacher %s -----
    name = %s
    age = %s
    sex = %s
    gongzi = %s
    kecheng = %s''' %(self.name,self.name,self.age,self.sex,self.gongzi,self.kecheng))
    class Student(Schoolmates):
    def __init__(self,name,age,sex,tuition,grade):
    Schoolmates.__init__(self,name,age,sex)
    self.tuition = tuition
    self.grade = grade
    def pay_tuition(self,amount):
    print("%s has paid %s" %(self.name,amount))
    def tell(self):
    print('''----- info student %s -----
    name = %s
    age = %s
    sex = %s
    tuition = %s
    grade = %s''' %(self.name,self.name,self.age,self.sex,self.tuition,self.grade))


    school= School("zjut","hangzhou")
    t1 = Teacher("老郭",40,"男",4000,"math")
    s1 = Student("小明",21,"男",5000,5)

    t1.tell()
    s1.tell()
    school.enroll(s1)
    school.hire(t1)
  • 相关阅读:
    使用密码解密TACACS+的报文
    C9K Stackwise Virtual(三)
    Webhook Configuration Example
    sup-bootflash和bootflash
    WLC5508 license没有500个?
    AAA Server Groups
    关于FlexConnect的Bug!
    Bug搬运工-CSCve57121--Cisco 2800, 3800 and 1560 series APs fail to pass traffic
    Bug搬运工-CSCvb29354-1810 OEAP cannot join vWLC
    阿里云云计算认证ACP模拟考试练习题第1套模拟题分享(共10套)
  • 原文地址:https://www.cnblogs.com/gaoxu366/p/7857656.html
Copyright © 2020-2023  润新知