CODE:
class Employee:
"所有员工的基类"
empCount=0
def __init__(self,name,salary):
self.name=name
self.salary=salary
empCount+=1
ERROR:
UnboundLocalError: local variable 'empCount' referenced before assignment
CORRECT:
empCount+=1 改为 Employee.empCount+=1
NOTE:
class的attribute不能单独存在,必须依附class,才有class.attribute