My Generator Paradox!

vbgunz vbgunz at gmail.com
Fri Mar 17 14:44:20 EST 2006


I believe I understand now. the yield keyword is sort of like a cousin
to return. return will bring back an object I can work with and so does
yield *but* yield's object will most likely support the .next() method.

So, if I worked with a function that ends with the return keyword and
it returns a list, I can run list operations and list methods on it. if
a function ends with the yield keyword a generator should return.

So, calling the function by it's name will always reset and initialize
the generator. Whereas assigning to the functions yielded return grants
access to the real generator in which I can use the next() method.

Maybe I've explained it wrong *but* it does make sense to me now. I
just couldn't grasp it because I am still new to the keyword yield and
didn't know it sort of works like return.

I really wish to thank you fellas so much for your examples and
explanations! I think I got it! I thank you all again!




More information about the Python-list mailing list