组合
什么是组合?
1.继承:满足什么是什么的关系,is-a的关系
2.组合:就是一个对象拥有一个属性,该属性的值是另外一个对象
解决类与类之间的代码冗余问题
class People(): school = 'SH' def __init__(self, name, age, gender, ): self.name = name self.age = age self.gender = gender class Admin(People): pass class Course(): def __init__(self, name, period, price, ): self.name = name self.period = period self.price = price python = Course('python', '6mon', 10000) linux = Course('linux', '5mon', 20000) class Student(People, Course): def __init__(self, name, age, gender, course=None): if course is None: course = [] self.courses = course super().__init__(name, age, gender, ) def choose_course(self, stu_obj, course): stu_obj.courses.append(course)