[Python-ideas] PEP 572: about the operator precedence of :=

Guido van Rossum guido at python.org
Thu May 10 09:53:40 EDT 2018

On Thu, May 10, 2018 at 3:32 AM, Terry Reedy <tjreedy at udel.edu> wrote:

> On 5/9/2018 11:33 PM, Guido van Rossum wrote:
> I now think that the best way out is to rule `:=` in the top level
>> expression of an expression statement completely
> I would like to be able to interactively enter
> >>> a: = f(2,4)
> to have 'a' echoed as well as bound.

I hope that's a typo (the can be no space between `:` and `=`, since `:=`
is a single token, just like `<=').

We *could* make this work while still ruling out the ambiguous cases (which
involve top-level commas on either side of the assignment expression).

OTOH I worry that this particular feature would cause `:=` to become part
of many a teacher's bag of tricks to show off, exposing users to it way too
early for any curriculum, and it might then elicit complaints that

>>> def f():
...     a := 5
>>> f()

doesn't print `5`.

So all in all I'm not sure I think this is important enough to support, and
the rule "Use `:=` in expressions, not as a top level assignment" seems
easier to explain and understand.

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180510/dd23afc8/attachment-0001.html>

More information about the Python-ideas mailing list