[Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

Alan Gauld alan.gauld at btinternet.com
Tue Aug 6 10:44:51 CEST 2013


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/



More information about the Tutor mailing list