7_26 day 27 14min迭代器协议

class Foo:
def __init__(self,n):
self.n=n
def __iter__(self):
return self

def __next__(self):
if self.n == 13:
raise StopIteration('终止了')
self.n+=1
return self.n

# l=list('hello')
# for i in l:
# print(i)
f1=Foo(10)
# print(f1.__next__())

猜你喜欢

转载自www.cnblogs.com/yikedashuyikexiaocao/p/9369560.html
今日推荐