yield
km
km at mrna.tn.nic.in
Sat Jan 17 13:15:10 EST 2004
Hi gerrit,
i ran the snippet but i am sorry, i couldnt get what u were saying.
kindly enlighten,
regards,
KM
---------------------------------------------------------------------
On Sat, Jan 17, 2004 at 05:59:21PM +0100, Gerrit Holl wrote:
> > i didnt understand the purpose of 'yield' keyword and the concept of 'generators' in python. can someone explain me with a small example how generators differ from normal function calls?
> > kindly enlighten
>
> You can see 'yield' as a continuable function:
>
> def f():
> yield time.time()
> yield time.time()
> yield time.time()
>
> now f() will return a generator, with a .next() method. Try:
> g = f()
> g.next()
> g.next()
> g.next()
>
> on the interactive prompt, and see what happens...
>
> yours,
> Gerrit.
>
> --
> Mozilla _is_ the web: it grows faster than you can download it.
> 1011001 1101111 1110101 1110010 1110011 0101100
> 1000111 1100101 1110010 1110010 1101001 1110100
--
More information about the Python-list
mailing list