Oddity with 'yield' as expression - parentheses demanded

C

Chris Angelico

Was playing around with yield inside a lambda and ran into a distinct oddity.

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600
32 bit (Intel)] on win32return yield(x)
SyntaxError: invalid syntaxx=yield(x)
return x
If yield is an expression, why does it need extra parentheses around
it? [1] suggest that "(yield x)" is an expression that can elide the
parens only when it "is the sole expression on the right hand side of
an assignment statement", and presumably there's a similar rule
allowing the non-expression form "yield x" to omit the parens. Why is
this so? Why is it not simply an expression on its own?

[1] http://docs.python.org/3.3/reference/expressions.html#grammar-token-yield_expression

ChrisA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top