Why = = (and not just =)
John Roth
newsgroups at jhrothjr.com
Sun Oct 19 17:23:38 EDT 2003
"Joe Green" <someone at microsoft.com> wrote in message
news:3f92eb51$0$259$cc9e4d1f at news.dial.pipex.com...
> 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:) ?
Part of the reason is that Guido very seldom burns his bridges,
even after he's crossed them. Comparison and assignment are
different operators, and they deserve a different operator symbol.
Fortran started the trend of using the same symbol, but Fortran
was unrepentently statement oriented, and had a rather restricted
expression syntax to boot. The original language in the Algol family,
Algol 60, used ":=" as the assignment operator as I recall, a tradition
followed by Pascal.
Frankly, I'd rather have the assignment operator be something
like a left arrow: "<-" perhaps. I think it makes more sense,
and it avoids the confusion between one = and two.
It also allows the developers to add an assignment in expressions
sometime. Not that I think there's much hope of that, but it does
keep the options open.
John Roth
>
>
More information about the Python-list
mailing list