A Summary: Expression-Assignments. (Very Long)

Michael P. Reilly arcege at shore.net
Wed May 12 10:29:57 EDT 1999


Adrian Eyre <a.eyre at optichrome.com> wrote:
:> Unlike C and Perl, in Python the code 'a=b' is a statement, not an
:> expression. That means it does not return any value, [snip]

: Actually, I find this part of Python a bit inconsistent since:

: a=b=1 is valid while
: a=(b=1) is not...

: To me the fact that 'a=b=1' works implies that the 'b=1' bit is
: actually returning a value. This should perhaps be more consistent
: in Python by either making 'a=b=1' illegal, or making 'a=(b=1)' legal.

It is consistent with Python and with other languages.  Parentheses
denote an expression, so a=(...) assigns an expression to `a'.  Since
assignments are illegal within expressions in Python, this is a syntax
error.  Since in most languages, assignment reads from right to left,
having 'a=b=1' can be said to be consistent too.

Myself, I did have some inconsistency issues with `a=b=1' when I first
learned Python.  But it's a nice to have and not something I'll complain
about if it is taken away.

  -Arcege





More information about the Python-list mailing list