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