call函数
使用call方法实现1100的累加和
class Person:
def init(self):
pass
def __call__(self,num):
he=0
for i in range(1,num+1):
he+=i
print(he)
person=Person()
person(100)
运行截图:
call函数
使用call方法实现1100的累加和
class Person:
def init(self):
pass
def __call__(self,num):
he=0
for i in range(1,num+1):
he+=i
print(he)
person=Person()
person(100)
运行截图: