class Fibs: def __init__(self): self.a = 0 self.b = 1 def __next__(self): self.a, self.b = self.b, self.a + self.b return self.a def __iter__(self): return self fibs = Fibs() for f in fibs: if f > 500: # 输出 截止 大于500的斐波那锲数 print(f, end='\t') break else: print(f, end='\t')
标签:__,锲数,self,斐波,500,def From: https://www.cnblogs.com/sangern/p/17392555.html