class Employee:
'所有员工的基类'
empCount = 0
empSumSalary = 0
def __init__(self, name, salary,title):
self.name = name
self.salary = salary
self.title = title
Employee.empCount += 1
Employee.empSumSalary += salary
#@property
def displayEmployee(self):
print ("Name : ", self.name, ", Salary: ", self.salary,"title: ",self.title)
@classmethod
def total(cls):
print("Total: {0}".format(cls.empCount))
"创建 Employee 类的3个对象"
emp1 = Employee("Zara", 2000,"PM")
emp2 = Employee("Manni", 5000,"Analyst")
emp3 = Employee("Ke",9000,"Data Analyst")
emp1.displayEmployee()
emp2.displayEmployee()
emp3.displayEmployee()
Employee.total()
#print ("Total Employee %d" % Employee.empCount,Employee.empSumSalary)
To embed this project on your website, copy the following code and paste it into your website's HTML: