使用了__CALL__简化哪里了,跟__len__这节的代码比,没看到差别呀
class Fib(object): def __init__(self): self.res = [] def __call__(self, num): a = 0 b = 1 for x in range(num): self.res.append(a) a, b = b, a + b return self.res f = Fib() print(f(10))
class Fib(object): def __init__(self): self.res = [] def __call__(self, num): a = 0 b = 1 for x in range(num): self.res.append(a) a, b = b, a + b return self.res f = Fib() print(f(10))
2021-03-29
举报