14 python python-2.6
我注意到Python2.6在它的全局函数列表中添加了next().
Run Code Online (Sandbox Code Playgroud)Retrieve the next item from the iterator by calling its next() method.如果
default给定,则在迭代器耗尽时返回,否则StopIteration引发.
添加这个的动机是什么?你能做什么next(iterator),你不能做什么iterator.next()和一个except条款来处理StopIteration?
Man*_*ron 10
请注意,在Python 3.0+中,该next方法已重命名为__next__.这是因为一致性.next是一种特殊方法,特殊方法按惯例命名(PEP 8),带有双前导和尾随下划线.特殊方法并不是直接调用的,这就是next引入内置函数的原因.