Python Learning Day Eighth-school (inheritance of Class)

Source: Internet
Author: User

1 #Coding=utf-82 #Version:python 3.6.03 #tools:pycharm 2017.3.24_date_ ='2018/4/25/025 21:02'5 6 classSchool (object):7     def __init__(SELF,NAME,ADDR):8Self.name =name9SELF.ADDR =AddrTenSelf.students = [] OneSelf.teachers = [] ASelf.staffs = [] -  -     defEnroll (self,stu_obj): the         Print("Student%s enrolls in"%stu_obj.name) - self.students.append (stu_obj) -  -     defHire (self,staff_obj): + self.staffs.append (staff_obj) -         Print("Hire new Staff%s"%staff_obj.name) +  A classSchoolmember (object): at     def __init__(self,name,age,sex): -Self.name =name -Self.age = Age -Self.sex =Sex -  -     defTell (self): in         Pass -  to classTeacher (schoolmember): +     def __init__(self,name,age,sex,salary,course): -Super (Teacher,self).__init__(Name,age,sex) theSelf.salary =Salary *Self.course =Course $ Panax Notoginseng     defTell (self): -         Print(" " the -----Info of teacher:%s----- + name:%s A age:%s the sex:%s + salary:%s - course:%s $         " "%(self.name,self.name,self.age,self.sex,self.salary,self.course)) $  -     defTeach (self): -         Print("%s is teaching%s"%(self.name,self.course)) the  - classStudent (schoolmember):Wuyi     def __init__(self,name,age,sex,stu_id,grade): theSuper (Student,self).__init__(Name,age,sex) -self.stu_id =stu_id WuSelf.grade =Grade -  About     defTell (self): $         Print(" " - -----Info of student%s----- - name:%s - age:%s A sex:%s + stu_id:%s the grade:%s -         " "%(Self.name,self.name,self.age,self.sex,self.stu_id,self.grade)) $  the     defPay (self,amount): the         Print("%s has paid tution for $%s"%(self.name,amount)) the  theSchool = School ("Hnust","Xiangtan") -T1 = Teacher ("Adam", 28,"male", 200000,"python") inT2 = Teacher ("Eva", 28,"female", 200000,"Music") theS1 = Student ("Alex", 22,"male", 1404020422,"opp-1") theS2 = Student ("Eason", 19,"male", 1404020423,"opp-2") About  the T1.tell () the S1.tell () the school.hire (t1) + school.hire (T2) - School.enroll (S1) the school.enroll (S2)Bayi  the Print(school.students) the Print(school.staffs) -  - School.staffs[0].teach () the  forStuinchschool.students: theStu.pay (500)
View Code
E:\ProgramData\Anaconda3\python.exe d:/python_proc/s14/week6/day1/Inheritance-School. PY        -----Info of Teacher:adam-----        name:adam        age:28        sex:male        salary:200000        course:python                -----Info of Student Alex-----        Name:alex        age:22        sex:male        stu_id:1404020422        grade:opp-1        Hire new staff Adamhire new Staff evastudent Alex enrolls instudent Eason enrolls in[<__main__.student object at 0x0000028f0a59d8d0>, <__mai N__.student object at 0x0000028f0a59d908>][<__main__.teacher object at 0x0000028f0a59d860>, <__main__. Teacher object at 0x0000028f0a59d898>]adam is teaching Pythonalex have paid tution for $500eason have paid tution for $ 0Process finished with exit code 0

  

Python Learning Day Eighth-school (inheritance of Class)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.