面向对象的进阶(组合和继承)
初始面向对象之后,我们来学习面向对象的三大特性以及面向对象的其他补充方面的知识。 组合 组合只有一个例子因为组合只作为上一章的补充内容 #老师 课程 生日 class Course: def __init__(self,name,period,price): self.name = name self.period = period self.price = price class Birth: def __init__(self,year,month,day): self.year = year self.month = month self.day = day class Teacher: def __init__(self,name,salary,boy_friend,python): self.name = name self.salary = salary self.bf = boy_friend self.course = python python = Course('python','6 months',20000) egg = Teacher('egon',200,'yuan',python) print(egg.bf) print(egg.name) print(egg.course.name) egg_birth = Birth(1965,2,2) print