python迭代器是什么百度百科,python迭代器的接口是什么?
生活随笔
收集整理的這篇文章主要介紹了
python迭代器是什么百度百科,python迭代器的接口是什么?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
What are the required methods for defining an iterator? For instance, on the following Infinity iterator, are its methods sufficient? Are there other standard or de factor standard methods that define an iterator?
class Infinity(object):
def __init__(self):
self.current = 0
def __iter__(self):
return self
def next(self):
self.current += 1
return self.current
解決方案
What you have is sufficient for Python 2.x, but in Python 3.x you need to define the function __next__ instead of next, see PEP 3114.
If you need code that is compatible with both 2.x and 3.x, include both.
總結
以上是生活随笔為你收集整理的python迭代器是什么百度百科,python迭代器的接口是什么?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle查询cpu占用率高,解决or
- 下一篇: 实体类blob类型_Mysql的数据类型