from collections.abc import Iterator#编写一个迭代器,通过循环语句,实现对某个正整数的依次递减1,直到0.class Descend(Iterator):def __init__(self,N):self.N=Nself.a=0def __next__(self):while self.a<self.N:self.N-=1return self.Nraise StopIterationdescend_iter=Descend(10)try:for i in descend_iter:print(i)except StopIteration as e:print('迭代结束')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。