[Python-Dev] PEP 572: Assignment Expressions

Paul Moore p.f.moore at gmail.com
Tue Apr 17 13:14:00 EDT 2018


On 17 April 2018 at 16:12, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 04/17/2018 06:26 AM, Paul Moore wrote:
>
>> I should also point out that I remain -0 on this proposal (I'd already
>> said this on python-ideas, but I should probably repeat it here). For
>> me, the use cases are mostly marginal, and the major disadvantage is
>> in having two forms of assignment. Explaining to a beginner why we use
>> a := b in an expression, but a = b in a statement is going to be a
>> challenge.
>
>
> I don't see the challenge:  They are different because '=' came first, but
> using '=' in an expression is a common source of bugs, so there we use ':='
> instead.

I fully expect the question "so if I want to assign to a variable, why
shouldn't I just use x := 12 (as a statement)?" I don't have a good
answer for that. And if I can't come up with a convincing reply to
that, the next question will likely be "so why does = exist at all?"

If we want to change Python so that assignments are expressions, and
assignment statements only remain for backward compatibility, then
fine - we should propose that (I'd probably be against it, BTW, but
I'd reserve judgement until I saw a proper proposal) but this PEP
would need a lot of changes if it were to go down that route. This
half-way house of having both seems like it will just confuse people.

Paul


More information about the Python-Dev mailing list