test.py 629 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. class Employee:
  4. '所有员工的基类'
  5. empCount = 0
  6. def __init__(self, name, salary):
  7. self.name = name
  8. self.salary = salary
  9. Employee.empCount += 1
  10. def displayCount(self):
  11. print "Total Employee %d" % Employee.empCount
  12. def displayEmployee(self):
  13. print "Name : ", self.name, ", Salary: ", self.salary
  14. "创建 Employee 类的第一个对象"
  15. emp1 = Employee("Zara", 2000)
  16. "创建 Employee 类的第二个对象"
  17. emp2 = Employee("Manni", 5000)
  18. emp1.displayEmployee()
  19. emp2.displayEmployee()
  20. print "Total Employee %d" % Employee.empCount