标签:alt elf 图片 lazy cal a+b load sel obj
定义了call方法的对象,称为可调用对象,即该对象可以像函数一样调用
a = 30
b = 50
c = a+b ===>c = a.__add__(b)
obj() ====>__call__
1 class SalaryAcount: 2 def __call__(self, salary): 3 yearSalary = salary*12 4 MouthSalary = salary 5 daySalary = salary//22.7 6 hourSalary = daySalary//8 7 8 return dict(yearSalary=yearSalary,MouthSalary=salary,daySalary=daySalary,hourSalary=hourSalary) 9 10 s = SalaryAcount() 11 print(s(30000))
Python12-06_面向对象----__call__方法和可调用对象
标签:alt elf 图片 lazy cal a+b load sel obj
原文地址:https://www.cnblogs.com/xujie-0528/p/13661523.html