本文摘自php中文网,作者黄舟,侵删。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | >>> g = (x * * 2 for x in range ( 10 ))
>>> next (g)
0
>>> next (g)
1
>>> next (g)
4
>>> next (g)
9
>>> next (g)
16
>>> next (g)
25
>>> next (g)
36
>>> next (g)
49
>>> next (g)
64
>>> next (g)
81
>>> next (g)
Traceback (most recent call last):
File "<stdin>" , line 1 , in <module>
StopIteration
|
每次调用next,迭代一下迭代器,到最后会触发StopIteration错误。
以上就是python迭代器中next()的用法示例的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python爬虫获取图片并下载保存至本地
学Python下什么软件
如何查看Python源代码
Python实现简单淘宝秒杀功能
Python学习法则
Python中的组合数据类型可以分为哪三类
Python编程学来做什么
详解在Python中执行系统命令的方法
Python中matplotlib实现绘制3d图方法介绍
Python 怎么把set转成list
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python迭代器中next()的用法示例