[Python-ideas] PEP 572 version 2: Statement-Local Name Bindings

Guido van Rossum guido at python.org
Fri Mar 23 12:58:13 EDT 2018


I also think it's fair to at least reconsider adding inline assignment,
with the "traditional" semantics (possibly with mandatory parentheses).
This would be easier to learn and understand for people who are familiar
with it from other languages (C++, Java, JavaScript).

On Fri, Mar 23, 2018 at 9:34 AM, Christoph Groth <christoph at grothesque.org>
wrote:

> Disclaimer: I skimmed/searched through the PEP 572 threads (or should I
> say "literature"?) and did not find a discussion of the following point.
> If it has been discussed already, I'd be glad to be pointed to it.
>
> I am aware that Python, in contrast to C-like languages, has chosen not
> to treat assignments (=) as an expression with a value.  The motivation
> for this is to avoid bugs due to confusion with the equality operator
> (==).
>
> But wouldn't it be a good alternative to PEP 572 to *add* an assignment
> operator that is an expression to Python, and is distinct from "=", for
> example ":="?  Then, instead of PEP 572's:
>
>     stuff = [[(f(x) as y), x/y] for x in range(5)]
>
> one could write
>
>     stuff = [[(y := f(x)), x/y] for x in range(5)]
>
> In difference to PEP 572, the variable y would not be statement-local,
> which IMHO would be a welcome simplification.  (PEP 572 introduces a
> third class of variables to Python.)
>
> Overall, it seems to me that introducing a new operator ":=" would serve
> the same purpose as PEP 572, but in a simpler and arguably cleaner way,
> while eliminating the risk of confusion with "==".  The operator "="
> would be left around, but could be deprecated in Python 5 and removed in
> Python 6.  It would certainly suit a language that is widely used in
> education to sharpen the distinction between assignment and equality
> operators.
>
> Cheers,
> Christoph
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



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


More information about the Python-ideas mailing list