斐波那契额数列
class Fib(object): def __init__(self, num): self.num = num self.fib = [] if self.num == 1: self.fib = [0] elif self.num == 2: self.fib = [0, 1] else: self.fib = [0, 1] for i in range(2, self.num): self.fib.append(self.fib[i-1] + self.fib[i-2]) def __str__(self): return str(self.fib) def __len__(self): # return self.num return len(self.fib) f = Fib(10) print(f) print(len(f))