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

Steven D'Aprano steve at pearwood.info
Fri May 11 13:27:25 EDT 2018


On Thu, May 10, 2018 at 09:53:40AM -0400, Guido van Rossum wrote:

[...]
> 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.

Like Terry, I too would find it useful to be able to use x := expression 
in the interactive interpreter to see the value immediately.

But I'd rather start off by prohibiting := as a stand-alone statement, 
and relax the restriction later, than by allowing it and then regretting 
it later.

I think the rule "binding expressions are prohibited as a stand-alone 
statement" might reduce some of the anxiety about having two ways to do 
assignment, even if the cost is that they are treated as a special case. 
(All other expressions are allowed as statements, even if they're 
pointless.)



-- 
Steve


More information about the Python-ideas mailing list