[Python-ideas] Python-ideas Digest, Vol 131, Issue 106

Steven D'Aprano steve at pearwood.info
Tue Oct 31 13:31:07 EDT 2017

On Tue, Oct 31, 2017 at 10:31:50AM +0000, אלעזר wrote:

> Off topic: why can't we simply allow something like this:
>     (the_bob) = (name for name in ('bob','fred') if name=='bob')

Parens don't make a tuple. They are just for grouping. If you want a 
tuple, you need a comma:

    the_bob, = ...

with or without the parens. It would be terribly surprising if (x) was a 
sequence on the left hand side but not on the right hand side of an 

> Why does Python treat the parenthesis at the LHS as grouping parens?
> operators are not allowed anyway; (a + (b + c)) = [1] is syntax error.

a, (b, c), d = [1, "xy", 2]

> Currently
>     (x) = 1
> works, but I can't see why should it.

Why shouldn't it?

Its just a trivial case of the fact that the left hand side can be 
certain kinds of expressions, some of which require parens:

    (spam or ham)[x] = value

There are lots of possible expressions allowed on the LHS, and no good 
reason to prohibit (x) even though its pointless.


More information about the Python-ideas mailing list