python迭代器中next()的用法示例


本文摘自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》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...