继承是 什么是什么的关系
老师有课程: 有的关系是组合
学生有生日 有的关系是组合
老师增加课程属性=课程对象
#_*_coding:utf-8_*_
class People:
school='luffycity'
def __init__(self,name,age,sex):
self.name=name
self.age=age
self.sex=sex
class Teacher(People):
def __init__(self,name,age,sex,level,salary,):
super().__init__(name,age,sex)
self.level=level
self.salary=salary
def teach(self):
print('%s is teaching' %self.name)
class Student(People):
def __init__(self, name, age, sex, class_time,):
super().__init__(name,age,sex)
self.class_time=class_time
def learn(self):
print('%s is learning' % self.name)
#课程
class Course:
def __init__(self,course_name,course_price,course_period):
#课程名字
self.course_name = course_name
self.course_price = course_price
self.course_period = course_period
def tell_info(self):
print('课程名<%s> 课程价钱<%s> 课程周期<%s>' %(self.course_name,self.course_price,self.course_period))
class Date:
def __init__(self,year,mon,day):
self.year=year
self.mon=mon
self.day=day
def tell_info(self):
print('%s-%s-%s' %(self.year,self.mon,self.day))
# teacher1=Teacher('alex',18,'male',10,3000,)
# teacher2=Teacher('egon',28,'male',30,3000,)
# python=Course('python',3000,'3mons')
# linux=Course('linux',2000,'4mons')
#python课程名字
# print(python.course_name)
#老师教python课程 老师的对象定制一个课程的属性(course就是属性) ,让这个属性指向另外实例的对象
# teacher1.course=python
# teacher2.course=python
# print(python)
# print(teacher1.course)
# print(teacher2.course)
# print(teacher1.course.course_name)
# print(teacher2.course.course_name)
#
#让老师有一个属性,去指向实例对象
#
# teacher1.course.tell_info()
# student1=Student('张三',28,'female','08:30:00')
# student1.course1=python
# student1.course2=linux
# student1.course1.tell_info()
# student1.course2.tell_info()
# student1.courses=[]
# student1.courses.append(python)
# student1.courses.append(linux)
#学生
student1=Student('张三',28,'female','08:30:00')
#日期
d=Date(1988,4,20)
#python课程
python=Course('python',3000,'3mons')
#bird就是属性
student1.birh=d
student1.birh.tell_info()
student1.course=python
student1.course.tell_info()