On 06/08/13 09:26, Steven D'Aprano wrote:

All this is correct, but yield is more powerful than that. Not only does
yield get used to return values from a function, it also gets used to
send values *into* a running function.

Yikes. This is new to me too.
When did that happen? Has yield always had these two way powers?

py> def cr():  # Co-Routine.
...     x = yield()
...     while True:
...             x = yield(x + 1)
...
py> magic = cr()
py> magic.send(None)
()
py> magic.send(1)
2

Prepare to have your mind expanded

I have some reading to do...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to