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爬虫获取图片并下载保存至本地

Python下什么软件

如何查看Python源代码

Python实现简单淘宝秒杀功能

Python学习法则

Python中的组合数据类型可以分为哪三类

Python编程学来做什么

详解在Python中执行系统命令的方法

Python中matplotlib实现绘制3d图方法介绍

Python 怎么把set转成list

更多相关阅读请进入《Python》频道 >>




打赏

取消

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

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

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

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

评论

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