class Employee:
'Common base class for all employees'
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
self.displaycount()
emp1 = Employee("Zara", 2000)
emp1.displayEmployee()
请注意
解释为三条逻辑线:
Python不会隐式地继续逻辑行。可以添加反斜杠作为显式继续:
但我认为最好使用适当的string formatting:
您还需要为访问方法使用正确的大小写(Python是区分大小写的),因此应该是:
或者,根据the style guide,将其命名为
display_count
相关问题 更多 >
编程相关推荐