[Python-ideas] PEP 572: Assignment Expressions (post #4)

Thautwarm Zhao yaoxiansamma at gmail.com
Thu Apr 12 23:00:47 EDT 2018


> You're looking at a very early commit there. I suggest looking at the
> most recent commits on one of two branches:

https://github.com/Rosuav/cpython/blob/statement-local-
variables/Grammar/Grammar
https://github.com/Rosuav/cpython/blob/assignment-
expressions/Grammar/Grammar

> Those are the two most recent states in my progress towards (a)
> statement-local name bindings with "EXPR as NAME", and (b) assignment
> expressions with "target := value".

Okay, and the syntax "target := value" seems to be much easier to handle
with.

I do support this feature, but now I'm worried about the meaning of ':=',
it seems to be a lazy assignment in some degree. I'm not sure using ':=' is
proper here.


> Inasmuch as I might like assignment expressions, it would only be in
while or if statements, personally.

Not exactly, assignment expression also works for "if expression", we can
now have null checking.

    var.method() if var:= function() else None

Null checking is importance enough to have a specific syntax in many other
languages(C#, kotlin, Ruby and so on), and we can even have more than null
checking by adding expression assignment.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180413/98028aef/attachment.html>


More information about the Python-ideas mailing list