Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Whatever goes inside a lambda must be an expression. The parentheses around yield make it a yield expression. Otherwise yield would be a statement which is a different thing as far as Python is concerned.

You can also use it inside generators:

  >>> def f():
         while True:
             xyz = (yield)
             print xyz
  >>> g = f()
  >>> g.next()
  # nothing happens as xyz == None
  >>> g.send('huhu')
  huhu


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: