[Python-ideas] PEP 572: about the operator precedence of :=
Terry Reedy
tjreedy at udel.edu
Thu May 10 16:05:41 EDT 2018
On 5/10/2018 9:53 AM, Guido van Rossum wrote:
> On Thu, May 10, 2018 at 3:32 AM, Terry Reedy
> <tjreedy at udel.edu
> <mailto: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 `<=').
a := f(2,4) # corrected ;-)
> 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,
until someone tries a := [0]*10000000
> 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`.
Although the reason the same as for any expression, I can believe that
people will see it as different. A bare assignment expression *looks*
like a statement in a way that other expressions do not.
> 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.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list