python学习——面向对象嵌套
''' 创建三个学校且三个学校的设施内容都是一直 ''' class School(object): def __init__(self,name,address): self.name = name self.address = address def speach(self): print('讲课') obj1 = School('北京','沙河') obj2 = School('上海','浦东') obj3 = School('深圳','南山') class Teacher(object): def __init__(self,name,age,salary): self.name = name self.age = age self.__salary = salary self.school = None t1 = Teacher('李杰',19,18888) t2 = Teacher('颜涛',18,60) t3 = Teacher('女神',18,600000) t1.school = obj1 t2.school = obj1 t3.school = obj2 print(t1.school.name) print(t1.school.address) t1.school.speach() print(t1.age)