>>> 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()的用法示例的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于python迭代器中next()的用法示例的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did84400