Assignment Versus Equality

BartC bc at
Sun Jun 26 06:48:30 EDT 2016

On 26/06/2016 08:36, Lawrence D’Oliveiro wrote:
> One of Python’s few mistakes was that it copied the C convention of using “=” for assignment and “==” for equality comparison.

One of C's many mistakes. Unfortunately C has been very influential.

However, why couldn't Python have used "=" both for assignment, and for 
equality? Since I understand assignment ops can't appear in expressions.

> It should have copied the old convention from Algol-like languages (including Pascal), where “:=” was assignment, so “=” could keep a meaning closer to its mathematical usage.

(I think Fortran and PL/I also used "=" for assignment. Both were more 
commercially successful than Algol or Pascal.)

> For consider, the C usage isn’t even consistent. What is the “not equal”
 > operator? Is it the “not” operator concatenated with the “equal” 
 > No it’s not! It is “!” followed by “=” (assignment), of all things!

I thought "!" /was/ the logical not operator (with "~" being bitwise not).

 > This fits in more with the following pattern:
>     A += B <=> A = A + B
>     A *= B <=> A = A * B
> in other words
>     A != B
> should be equivalent to
>     A = A ! B

Yes, that's an another inconsistency in C. Sometimes "<>" was used for 
"not equals", or "≠" except there was limited keyboard support for that. 
("/=" would have the same problem as "!=")

But again, that doesn't apply in Python as the "!=" in "A != B" can't 
appear in expressions.


More information about the Python-list mailing list