zoukankan      html  css  js  c++  java
  • 组合

    #组合
    #生成一个人的类
    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 tech(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 learn' % 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', 20, 'male', 10, 3000)
    teacher2 = Teacher('engin', 23, 'male', 30, 3000)
    student1 = Student('张三', 23, 'feamle', '08:30:12')
    python = Course('python', 3000, '4mons')
    linux = Course('linux', 2000, '3mons' )
    data = Date(1991, 2, 30)
    #把老师和学生共同拥有的课程或者生日的对象的类添加到老师或者学生的对象里面
    teacher1.course = python
    teacher2.coursr = python
    student1.course1 = python
    student1.course2 = linux
    student1.brih = data
    #用老师或者学生的对象直接调用生日或者课程的函数属性进行查找
    teacher1.course.tell_info()
    print(teacher1.course.course_name)
    print(teacher1.course)
    print(student1.course1)
    print(teacher2.coursr)
    print(python)
    python.tell_info()

    student1.course1.tell_info()
    student1.course2.tell_info()
    student1.course1 = []
    student1.course1.append(python)

    student1.brih.tell_info()



  • 相关阅读:
    CodeForces 404C Ivan and Powers of Two
    CodeForces 433C Ryouko's Memory Note-暴力
    if not
    python3的print函数
    交叉熵
    tensorflow一个很好的博客
    关于第几维的问题
    更新软件
    tensorflow训练代码
    tensorflow的一些函数
  • 原文地址:https://www.cnblogs.com/yuexijun/p/10244815.html
Copyright © 2011-2022 走看看