if <assignment>:

maney at pobox.com maney at pobox.com
Sun Nov 24 19:06:41 EST 2002


Mel Wilson <mwilson at the-wire.com> wrote:
>   We've just been there. groups.google.com can bring it all
> back, although I don't offhand remember the subject.

Which of three in the last ten days do you want?  :-)

>   Basically, assignments aren't possible within
> expressions.

More fundamentally, because assignment is a statement, not an operator,
in Python.

>   One good reason for this is list packing/unpacking in
> assignments:
> 
>        a, b = 5, 8
> 
>   As it stands, this is an assignment which effectively makes
> two 2-tuples equivalent, associating `a` with the value 5,
> and `b` with the value 8.
> 
>   If `b=5` were an allowable expression, then the statement
> above would change into a 3-tuple, and a useful piece of
> semantics would be a tad more awkward.

You are also assuming that operator= would have higher precedence than
the comma.  Offhand, that seems like a mistake that could be avoided,
although it may well not be the only such complication that would arise
if operator= were to be added.

>   You could think of making an exception for `if`
> statements, but beyond an uncertain point, exceptions are
> bad for a language

Right.  If it were to be done, t'would best be done consistently.

In theory, that point is between "none" and "any"; in practice, well,
in practice it's a little different than in theory.  :-/




More information about the Python-list mailing list