Python quiz

Feb 22, 2007 21:28

What does this line of code do?

if 0: yield None

(hint: it does something)

code

Leave a comment

Comments 6

egometry February 23 2007, 08:52:35 UTC
returns a not-null value?

...

...it'd help to know the language.

Reply

egometry February 23 2007, 09:35:54 UTC
Oh. The subject line.

...

...it'd help to know Python >_>

Reply


evilbob23 February 23 2007, 12:43:21 UTC
I have an image of a guy trying to get a prostitute to come home with him, but he's turned out his pockets and is frowning.

Reply


rizen February 23 2007, 18:54:17 UTC
So, the parts of python that do generators required the yield statement to have been parsed? You couldn't just replace that line with "pass"?

Reply

thespeedbump February 24 2007, 02:40:23 UTC
Right.

If a function has a yield statement somewhere in its body, it is considered to be a generator function. If no yield statement is ever executed, then the function is a generator that produces an empty sequence.

Reply

aubreyszutko August 11 2008, 13:43:00 UTC
If a function or method body contains the statement 'yield', then it becomes a -generator function-, and invoking the function returns a -generator iterator- instead of a simple value.

Reply


Leave a comment

Up