How to get one value at a time from a generator function in Python?

前端 未结 6 1955
鱼传尺愫
鱼传尺愫 2020-12-24 04:08

Very basic question - how to get one value from a generator in Python?

So far I found I can get one by writing gen.next(). I just want to make sure this

6条回答
  •  粉色の甜心
    2020-12-24 04:48

    This is the correct way to do it.

    You can also use next(gen).

    http://docs.python.org/library/functions.html#next

提交回复
热议问题