Attempting to understand yield as an expression

后端 未结 5 1815
猫巷女王i
猫巷女王i 2021-01-18 14:59

I\'m playing around with generators and generator expressions and I\'m not completely sure that I understand how they work (some reference material):

>>         


        
5条回答
  •  遥遥无期
    2021-01-18 15:13

    This generator translates into:

    for i in xrange(10):
        x = (yield i)
        yield x
    

    Result of second call to send()/next() are ignored, because you do nothing with result of one of yields.

提交回复
热议问题