迭代器

迭代器:

from collections import Iterator
isinstance('abc',Iterator)
a = iter('abc') #iter可以把序列类型变成Iteratable 类型
print(isinstance(a,Iterator))
print(a.__next__())
print(a.__next__())
print(a.__next__())






生成器用迭代器迭代:
from collections import Iterator
def func(n):
count=0
while count<n:
count+=1
yield count
print(count)
ss = func(3)
next(ss)
next(ss)
print(isinstance(iter(ss),Iterator))
next(ss)
 

posted on 2018-10-20 10:01  别离  阅读(69)  评论(0编辑  收藏  举报

导航