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