[Edu-sig] Equality and Assignment Notation

Kirby Urner urnerk@qwest.net
Sun, 7 Apr 2002 12:00:10 -0400


On Sunday 07 April 2002 01:04 pm, Josh McKenzie wrote:
> Hi
>
> Why does Python use the equal sign (=) to mean assignment, and use
> two equal signs (==) to mean equality? Equality and assignment are
> not the same, yet the meaning of the equal sign is universally
> understood, so why redefine its meaning?

Python likes to be spare with punctuation, so not surprising it
doesn't go for the standard PL/1 style alternative a := 3 (with 
colon) for assignment, just as it drops enclosing block braces 
(uses indentation) and semi-colon line terminators (optional 
if you want more than one statement per line).

APL had its own character set and so used <- (arrow) for 
assignment.

> I know other languages like Java and C++ employ this convention too,
> but how does one explain the logic behind this approach?
>

Very simply:  notations come and go; it's the ideas that are 
important.  If you have a difference, and a way of notating this
difference, then you're done.

Note that math books sometimes use the equal sign for assignment,
and sometimes to assert equivalence.  We're supposed to know
the different from context.  Parsers don't like 'context' so much
-- better to be explicit.

The use of a double equal makes sense in the light of other 
combos e.g. <= >= and !=.

Kirby

> I'll readily admit to a bias: when I see the notation ':=' in
> languages like Pascal, Smalltalk or Eiffel etc, I can at least
> understand the distinction these languages attempt to impart to the
> user that equality and assignment are similar, but distinct concepts.
>
> It may seem a trivial point to bring up, but while I can explain the
> difference between equality and assignment, I cannot explain the
> logic of using the '=' and '==' notation.
>
> Thanks :-)
>
> Regards - Josh M.
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
>
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig@python.org
> http://mail.python.org/mailman/listinfo/edu-sig