在介绍迭代器时候,首选介绍两个概念,
Iterable:可以直接作用于for循环的对象统称为可迭代对象
Iterator:可以被next函数调用并不断返回下一个值的对象称为迭代器
在集合数据类型中,list,dict,str等都是Iterable不是Iterator,下面通过代码展示
from collections.abc import Iterable
from collections.abc import Iterator
print(isinstance([], Iterable))
p