Surprise using the 'is' operator

Christophe chris.cavalaria at free.fr
Tue Sep 26 06:20:40 EDT 2006


codefire a écrit :
> Haha!
> 
> OK thanks guys.
> 
> I was just trying to check if objects were the same (object), didn't
> know Integers were a special case.

They are not a special case so much. It's just that "is" is extremly 
unreliable unless you're the one who created the objects. In the case of 
integers, it's the CPython implementation which constructs them as it 
sees fit and so, you cannot expect any kind of reliable "is" behavior.

When you are manipulating let's say lists, it gets much more reliable. 
You do know that the list you create by doing a = [] is not and will 
never be the same than the one you'll create later by doing b = []



More information about the Python-list mailing list