代码拉取完成,页面将自动刷新
"""
迭代器:实现了迭代协议的对象。
~ 魔术方法:__xxx__
~ __next__ / __iter__
上下文管理器:实现了上下文管理器协议的对象
~ __enter__ / __exit__
"""
# 1 1 2 3 5 8 13 21 34 55
class FibIter:
def __init__(self, num):
self.num = num
self.a, self.b = 0, 1
self.count = 0
def __iter__(self):
return self
def __next__(self):
if self.count < self.num:
self.a, self.b = self.b, self.a + self.b
self.count += 1
return self.a
raise StopIteration()
for value in FibIter(20):
print(value)
print(4181 / 6765)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。