class Person: def __init__(self): self.age = 1 def __call__(self, *args, **kwargs): print ‘age‘, self.age self.age += 1 return self person = Person() person()()() print type(person())
实例+()调用__call__,返回self,可实现循环调用.
知乎面试后端有问到.
C++/C 对语言而言的严格都才是足够高的.
时间: 2024-10-03 21:53:48