python - what does yield (yield) do?
Since python 2.5 there is the ability to send() , throw() , close() into a generator. Inside the defined generator one can 'catch' the sent data by doing something like: def gen(): while True: x = (yield) if x == 3: print('received 3!!') break else: yield x What i am trying to play with is doing something like: def gen2(): while True: yield (yield) Noticed that it is a legal generator which does something.. First thing i'm trying to figure out is: Is there a good usage for such writing? Also when doing something like: g = gen2() next(g) g.send(10) # output: 10 g.send(2) # output: nothing g