相关疑难解决方法(0)

为什么Python 2.6添加了一个全局的next()函数?

我注意到Python2.6在它的全局函数列表中添加了next().

next(iterator[, default])

Retrieve the next item from the iterator by calling its next() method.
Run Code Online (Sandbox Code Playgroud)

如果default给定,则在迭代器耗尽时返回,否则 StopIteration引发.

添加这个的动机是什么?你能做什么next(iterator),你不能做什么iterator.next()和一个except条款来处理StopIteration?

python python-2.6

14
推荐指数
2
解决办法
2392
查看次数

标签 统计

python ×1

python-2.6 ×1