[Edu-sig] Equality and Assignment Notation
Louis Bertrand
louis.bertrand@durhamc.on.ca
Tue, 9 Apr 2002 09:20:46 -0400
On April 8, 2002 12:00 pm, edu-sig-request@python.org mused=20
out loud:
> Why does Python use the equal sign (=3D) to mean
> assignment, and use two equal signs (=3D=3D) 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?
If you think you have trouble teaching a language with =3D=20
for assignment and =3D=3D for equality test, try SQL:
SELECT * FROM mytable WHERE name=3D'Guido'
gets all records in which the field name equals the string=20
'Guido';
Even better:
UPDATE mytable SET language=3D'Python' WHERE name=3D'Guido'
An assignment and an equality test in one statement.
I don't care what distinction is made (:=3D or =3D=3D), just make=20
one!
Ciao
--Louis
PS: Forbidding assignments in if and while statements is a=20
good idea, even if it's annoying. Try debugging code where:
if( x =3D 0) { /* stuff */ } was written for:
if( x =3D=3D 0) { /* stuff */ }=20
A good practice is to swap the terms: if( 0 =3D=3D x) { }
that way if you typo the =3D=3D to =3D, the compiler squawks.
Ciao
--Louis
--=20
Louis Bertrand <louis.bertrand@durhamc.on.ca>
School of Technology, Durham College
Oshawa, ON, Canada
+1.905.721.3111 x2468