标签:
>>> list = [1,2,3,4] >>> it = iter(list) #迭代器创建 >>> next(it) #访问迭代器,只能通过next()来访问,不能通过索引来访问 1 >>> next(it) 2 >>> next(it) 3 >>> next(it) 4 >>> next(it) Traceback (most recent call last): File "<pyshell#37>", line 1, in <module> next(it) StopIteration
list=[1,2,3,4] it = iter(list) # 创建迭代器对象 for x in it: print (x, end=" ")
输出结果:
1 2 3 4
标签:
原文地址:http://www.cnblogs.com/ping-y/p/5828345.html