Why = = (and not just =)

"Martin v. Löwis" martin at v.loewis.de
Sun Oct 19 16:19:46 EDT 2003


Joe Green wrote:
> Sorry, I cant help aking stupid questions:
> 
> I understand why we need = = in C, but why in Python (or Java),
> surely if you write
>  if a=b: pass # syntax error
> it could not possibly mean anything other than what I intended
> (which was of course if a = = b:) ?

Certainly, one could have use "=" to denote the test for equality.
However, I believe that this syntax was inherited from ABC, which
probably inherited it from C. In addition, it *is* useful to
syntactically distinguish between assignments and equality tests
even if the parser does not need that distinction: The human reader
might be tricked into seeing something that isn't there.

Regards,
Martin





More information about the Python-list mailing list