On Sat, 10 Aug 2013 20:21:46 -0700, Gary Herron wrote: > Our knee-jerk reaction to beginners using "is" should be: > Don't do that! You almost certainly want "==". Consider "is" an > advanced topic. > > Then you can spend as much time as you want trying to coach them into an > understanding of the precise details. But until they have that > understanding, they are well served by a rule-of-thumb that says: > Use "==" not "is" for comparisons.
"...except for comparing to None, where 99.99% of the time you do actually want an identity comparison." This can lead into a more detailed explanation for why you should choose one over the other, or the incurious newbie could take it is something to be learned by rote. I have no problem with telling newbies that there is a reason for this apparently arbitrary rule, but they don't need to learn it *right now* if they don't want. In any case, the rule can include "When in doubt, use equals". I'm good with that :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list