讲一组数据加上iter就形成了一个迭代器,例如:
a=[1,2,3,4,5,6,7,8,9,10]
b=iter(a)
那么此时b就是一个迭代器了,迭代器就只有一个方法,__next__(),例如:
b.__next__()
例如:
a=[1,2,3,4,5,6,7,8,9,10]
b=iter(a)
print(b.__next__())
print(b.__next__())
print(b.__next__())
print(b.__next__())
print(b.__next__())
print(b.__next__())
print(b.__next__())
print(b.__next__())
结果:
1
2
3
4
5
6
7
8