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

Chris Angelico rosuav at gmail.com
Fri Apr 13 07:28:17 EDT 2018


On Fri, Apr 13, 2018 at 9:17 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, Apr 12, 2018 at 07:28:28AM +1000, Chris Angelico wrote:
>
>> Fair enough. Also adding that chained assignment expressions should
>> generally be avoided.
>
> So long as its not a blanket prohibition, I'm good with that.
>
> Also, something like this:
>
>     spam := 2*(eggs := expression) + 1
>
> should not be considered a chained assignment.
>

Agreed. Chained assignment is setting the same value to two or more
targets, without any further changes or anything:

a = b = c = 0

Extremely handy as a statement (quickly setting a bunch of things to
zero or None or something), but less useful with expression
assignment.

Incidentally, I've only just made "x := y := 1" legal tonight
(literally during the writing of this post). Previously it needed
parentheses, and I just didn't see much priority on fixing something
that wasn't all that crucial :)

ChrisA


More information about the Python-ideas mailing list