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 <christ...@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@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to