美文网首页
10.Python3类的组合

10.Python3类的组合

作者: 一枼落知天下 | 来源:发表于2019-05-31 17:48 被阅读0次
    class School:
        def __init__(self,name,addr):
            self.name = name
            self.addr = addr
    
        @staticmethod
        def aboutUs():
            print("历史悠久,师资雄厚")
    
    class Teacher:
        def __init__(self,name,salary,time,school):
            self.name   = name
            self.salary = salary
            self.time   = time
            self.school = school
    
    class Course:
        def __init__(self,name,price,period,teacher,school):
            self.name   = name
            self.price  = price
            self.period = period
            self.teacher= teacher
            self.school = school
    
    
    s1 = School("帅府园汇","成都")
    s2 = School("帅府园汇","上海")
    s3 = School("帅府园汇","北京")
    
    
    t1 = Teacher("Adymo",10000,"8年",s1)
    t2 = Teacher("Aymly",10000,"8年",s2)
    t3 = Teacher("Bobdy",10000,"8年",s3)
    
    c1 = Course("Linux",10,"1h",t1,s1)
    
    print(c1.__dict__)
    
    
    

    相关文章

      网友评论

          本文标题:10.Python3类的组合

          本文链接:https://www.haomeiwen.com/subject/xrbgtctx.html