Python: Using static methods, the __STR__ function

Source: Internet
Author: User

Class man (object):     def __init__ (Self,name,phone):         self.name=name         self.phone=phone     def info_p (self):        return  " person %s has phone %s  "% (Self.name,self.phone) class student (man):     gpa_total = []    def __init__ (SELF,NAME,PHONE,GPA):         man.__init__ (Self,name,phone)          self.gpa=gpa        student.gpa_total.append (SELF.GPA)          @staticmethod          Def mean_gpa ():             return sum ( Student.gpa_total)  / float(Len (student.gpa_total))     def info_gpa (self):         reply = self. Info_p ()         reply +=  "\n      and is student with gpa %s  "%self.gpa          return reply     def __str__ (self):         return self.info_gpa () Class employee (man):     emp_total  = []    def __init__ (Self,name,phone,empolyee):         man.__init__ (Self,name,phone)              self.empolyee=empolyee        employee.emp_ Total.append (self.empolyee)          @staticmethod    &nbsP;    def total_salary ():             return sum (employee.emp_total)     def info_em (self):         reply = self. Info_p ()         reply +=  "\n    and  is an employee with salary %s "% (self.empolyee)          return replyclass staff (Employee):     def __init__ (Self, Name,phone,empolyee,staff):         employee.__init__ (Self,name,phone, Empolyee)         self.staff=staff     def  info_staff (self):         reply = self.info_em ()                  reply +=  "\n     and is staff with title  %s "%self.staff        return reply     Def __str__ (self):         return self.info_staff () class  professor (Employee):     def __init__ (Self,name,phone,empolyee,mingchen):         employee.__init__ (Self,name,phone,empolyee)          self.mingchen=mingchen    def info_m (self):         reply = self.info_em ()          reply +=  "\n     and is a professor assigned to  class %s "%self.mingchen        return reply     def __stR__ (self):         return self. Info_m () people = [student ("Sandy", "326-8324", 3.65), Student ("Jordan", "632-7434", 3.1), professor (" Leslie "," 985-2363 ", 50000.00," info 501 "), Staff (" Alex "," 743-4638 ", 25000.00," editor ")]print " these  are the people in the university:  "For person in people:     print personprint print  "Our total university payroll  budget is : " +str (Employee.total_salary ()) print " our average student  gpa is : " +str (Student.mean_gpa ())
these are the people in the university: person sandy has  phone 326-8324      and is student with gpa 3.65  person jordan has phone 632-7434      and is  Student with gpa 3.1 Person Leslie has phone 985-2363      and is an Employee with salary 50000.0      and is a Professor assigned to class Info 501Person  alex has phone 743-4638     and is an employee  with salary 25000.0     and is staff with title  editorour total university payroll budget is :75000.0our average  student gpa is :3.375 


This article is from the "knowledge is accumulated" blog, please be sure to keep this source http://goooood.blog.51cto.com/5060201/1579488

Python: Using static methods, the __STR__ function

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.