6. 增加類別方法
(1) Employee的類別方法
以下是一個例子:
class Employee():
highRate = 0.23
lowRate = 0.19
@classmethod
def regularTax(cls, income):
if income > 40000:
return int(income*cls.highRate)
else:
return int(income*cls.lowRate)
@classmethod
def parttimeTax(cls, income):
if income > 65000:
return int(income*cls.highRate)
else:
return int(income*cls.lowRate) 呼叫類別方法:
執行結果:
說明:
