class Employee:
empCount=0 def __init__(self, name,salary):
self.name=name
self.salary=salary
Employee.empCount+=1 def displayCount(self):
print "Total Employee %d" %Employee.empCount def displayEmployee(self):
print "Name:",self.name,",salary:",self.salary emp1 = Employee("zara" , 2000) emp2 = Employee("manni" , 3000) emp1.displayEmployee() emp2.displayEmployee()
答案 0 :(得分:1)
这是您的代码格式化方式:
class Employee:
empCount = 0
def __init__(self, name, salary):
self.name = name
self.salary = salary
Employee.empCount += 1
def displayCount(self):
print "Total Employee %d" % Employee.empCount
def displayEmployee(self):
print "Name:", self.name, ",salary:", self.salary
emp1 = Employee("zara", 2000)
emp2 = Employee("manni", 3000)
emp1.displayEmployee()
emp2.displayEmployee()
现在它有效,你唯一的错误就是不按照PEP8风格指南编写