Fun Python question

What does this do?
def func():
  print 'foo'
  yield 'bar'

print func()
Take a guess, then give it a try.

1 comment:

Kevin said...

in lieu of the print func() line, you could do:

for dummy in func(): pass

I've never really played with yield as I don't think it makes things very clear. And this bit of code is a good example why (though I suspect it's partially due to how python implements the construct).