Why do we need ==?

John Roth johnroth at ameritech.net
Mon Dec 9 07:44:33 EST 2002


"M" <marvelan at hotmail.com> wrote in message
news:c0abefc3.0212090428.202ae1a2 at posting.google.com...
> Just doing some thinking....
>
> Why do Python use the == syntax for comparison?
>
> As assignment inside an if is not possible would not
> comparison could be done with just one =?
>
> Why can't we do:
>
> if a = 1:
>     print "Foo"
>
> instead of
>
> if a == 1:
>    print "Bar"
>
> ???
> I think a
>
> if a equal 1:
>    print "Foo"
>
> is better instead of == (which does not carry any clue as to what they
> do) if one single = is not possible...
>
> ok, I'm not saying we should change Python right now. Just curious...

It's a familiarity thing. Having different symbols for assignment and
comparison is useful. I would personally prefer a left pointing arrow
for assignment and a single equal sign for comparison, but there isn't
any such character on most keyboards. I also liked Pascal's practice
of using := for assignment, but that doesn't seem to have caught on
in the wider community.

Familiarity is useful. A double == for comparison is standard across
a wide variety of languages.

Besides which, it doesn't foreclose the option of adding assignment
in expressions if Guido ever changes his mind about it. Granted, that's
very unlikely to ever happen.

John Roth





More information about the Python-list mailing list