首页 > 编程语言 > 详细

《Python Cookbook v3.0.0》Chapter4 迭代器、生成器

时间:2021-08-21 20:05:03      阅读:16      评论:0      收藏:0      [点我收藏+]

感谢:
https://github.com/yidao620c/python3-cookbook
如有侵权,请联系我整改。

本文章节会严格按照原书(以便和原书对照,章节标题可能会略有修改),内容会有增删。

4.1 手动遍历迭代器

>>> items
[1, 2, 3]
>>> it=iter(items)
>>> it
<list_iterator object at 0x0000024B94D25408>
>>> next(it)
1
>>> next(it)
2
>>> next(it)
3
>>> next(it)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
StopIteration
>>> it=iter(items)
>>> next(it)
1
>>> print(*it)
2 3
>>> print(*it)

《Python Cookbook v3.0.0》Chapter4 迭代器、生成器

原文:https://www.cnblogs.com/Code2235/p/15170265.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!