What are the iteration class methods next() and __next__() for, and what is the difference?

后端 未结 2 1191
误落风尘
误落风尘 2021-01-17 15:13

I am a little bit lost on python iterators. I occasionally use them, but I don\'t remember creating one myself. I read from somewhere that I don\'t remember where, a code li

相关标签:
2条回答
  • 2021-01-17 15:59

    PEP 3114 renamed iterator.next() to iterator.__next__(). This was implemented in version 3.0. The link above contains all the gory details.

    0 讨论(0)
  • 2021-01-17 16:03

    next has been renamed to __next__ in Python 3. As for what it does, it should return the next item, or raise StopIteration if there are no more.

    0 讨论(0)
提交回复
热议问题