# 先写个迭代器文件 iterator.py
class Fib:
def __init__(self):
self.n1 = 0
self.n2 = 1
def __next__(self):
self.n1, self.n2 = self.n2, self.n1 + self.n2
return self.n1
def __iter__(self):
return self
python3 迭代器实现斐波那契数列
最新推荐文章于 2024-02-20 17:31:32 发布