Thread: Python brevity
View Single Post
Old May 22nd, 2006, 10:55 AM   #9
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by DaWei
I am a total Python noob. That means ignorant, or uninformed; not stupid. Please do not mislead me while I'm trying to learn, whether it's to promote yourself as a guru, or high-priest, or for any other reason.
Sorry, I merely misunderstood what you were asking.

I thought you were asking why "x is not y" is used instead of "not (x is y)", a question that I've pondered before (because whilst "is not" makes sense in English, it makes less sense from a programming perspective). I didn't realise you were asking the difference between "==" and "is".

As for why "is" should be used instead of "==" for checking None, well, in most cases, it doesn't matter. However, Python objects can overide certain operators (as in C++), thus it's possible that an object will tell you that it is equal to None, without actually being None.

Using "is" ensures that the object really is (or is not) None in all circumstances.
Arevos is offline   Reply With Quote