python----迭代器

可以被next()调用并不断返回下一个值的对象称为迭代器:Iterator

  

iter() #可以将可迭代对象转变为迭代器
#可迭代对象:Iterable 
from collections import Iterable
print(isinstance(object_name,Iterable))#可以验证对象是否是一个 
                                                           Iterable对象
from clollections import Iterator
print(isinstance(object_name,Iterator))#可以用此方法验证对象是否为 
                                                            迭代器

 ***python3 的for 循环本质上是通过不断调用next()函数来实现循环的***

原文地址:https://www.cnblogs.com/goldapple/p/13113922.html