[Python-Dev] PEP 572: Assignment Expressions

Christoph Groth christoph at grothesque.org
Fri Apr 20 12:17:34 EDT 2018


Chris Barker - NOAA Federal wrote:

> > Personally, I even slightly prefer
> >
> > a := 3
> >
> > to the commonplace
> >
> > a = 3
> > because it visually expresses the asymmetry of the operation.
>
> Careful here! That’s a fine argument for using := in a new language,
> but people using := when they don’t need an expression because they
> like the symbol better is a reason NOT to do this.

Perhaps you are right and it is indeed unrealistic to expect people to
(eventually) shift to using := for simple assignments after 28 years of
Python...

Then I think it would be also OK to introduce a fully general ":=" but
discourage its use in assignment statements.  However, it seems strange
to forbid the use of one expression (namely ":=") as a statement while
all other expressions are allowed.  (So there seems no alternative to
accepting both = and := in statements, and if I understand you correctly
you consider this a problem.)

One way or the other, I'd like to underline a point that I made
yesterday: I believe that it's important for sanity that taking any
existing assignment statement and replacing all occurrences of "=" by
":=" does not have any effect on the program.

PEP 572 currently proposes to make ":=" a binary operator that is
evaluated from right to left.

Christoph


More information about the Python-Dev mailing list