10.Python3类的组合

2019-05-31  本文已影响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__)


上一篇 下一篇

猜你喜欢

热点阅读