>>> a=(x*3 for x in range(5))
>>> a._next_()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'generator' object has no attribute '_next_'
運行時出現上述錯誤,以爲是python版本問題,結果發現:
next前後的"_"是兩個連用
錯誤: _next_()
正確:__next__()
>>> a=(x*3 for x in range(5))
>>> a.__next__()
0
>>> a.__next__()
3
ok