本文摘自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检验jarque-bera是否符合正态分布
Python中pillow知识点学习
Python编程工具有哪些
Python字符串是可变类型吗
Python实现自定义顺序、排列写入数据到excel的方法
总结学习Python的思维导图介绍
Python中if有多个条件怎么办
Python字符串的操作方法
Python安装到哪个盘
解析Python利用pickle模块完成增删改查等一些功能
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python迭代器中next()的用法示例