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__())
posted @ 2018-07-26 04:36  一棵大树一棵小树一棵草  阅读(99)  评论(0)    收藏  举报