Yes, yield can also be obtained by sending to the generator:
>>> avg_gen = running_avg() >>> next(avg_gen)
Any value passed to the generator.send() method is returned by the yield expression. See yield documentation.
yield an expression was made in Python 2.5; before it was just a statement and only produced values ββfor the generator. By making the yield expression and adding .send() (and other methods to throw exceptions), you can now use simple coroutines ; see PEP 342 for initial motives for this change.
source share