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

David Mertz mertz at gnosis.cx
Thu Apr 12 18:50:06 EDT 2018


Fair enough. I wouldn't actually do what I suggested either. But then, I
also wouldn't ever write:

x1, x2 = (-b + sqrt(D)))/2, (-b - sqrt(D))/2 [with/where/whatever D=...]

If your goal is simply to have symmetry in the plus-or-minus clauses, I was
simply pointing out you can have that with the ':=' syntax.

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

On Wed, Apr 11, 2018, 5:09 PM Brendan Barnwell <brenbarn at brenbarn.net>
wrote:

> On 2018-04-11 11:05, David Mertz wrote:
> > How about this, Brendan?
> >
> > _, x1, x2 = (D := b**2 - 4*a*c), (-b + sqrt(D))/2, (-b - sqrt(D))/2
> >
> > I'm not sure I love this, but I don't hate it.
>
>         That's clever, but why bother?  I can already do this with
> existing Python:
>
> D = b**2 - 4*a*c
> x1, x2 = (-b + sqrt(D)))/2, (-b - sqrt(D))/2
>
>         If the new feature encourages people to do something like your
> example
> (or my earlier examples with the D definition inline in the expression
> for x1), then I'd consider that another mark against it.
>
> --
> Brendan Barnwell
> "Do not follow where the path may lead.  Go, instead, where there is no
> path, and leave a trail."
>     --author unknown
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180412/5ce2c6a2/attachment.html>


More information about the Python-ideas mailing list