Assignment Versus Equality

BartC bc at
Sun Jun 26 12:08:51 EDT 2016

On 26/06/2016 16:41, MRAB wrote:
> On 2016-06-26 11:48, BartC wrote:

>> However, why couldn't Python have used "=" both for assignment, and for
>> equality? Since I understand assignment ops can't appear in expressions.
> [snip]
> Python supports chained assignments. For example, "a = b = 0" assigns 0
> to both a and b.
> I'm not sure how common it is, though. I virtually never use it myself.

Well, if it's allowed, then it doesn't matter how common it is.

So "=" couldn't be used with a different meaning inside expressions as 
it would make this ambiguous.

It also raises the possibility of a bug when someone intends to write 
"a=b==0" but writes "a=b=c" instead.

In that case I would have supported the use of ":=" for assignment.


More information about the Python-list mailing list