需要帮助python构造函数获取输出作为类型错误

时间:2017-04-11 09:48:54

标签: python

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()

1 个答案:

答案 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风格指南编写