Surprise using the 'is' operator
Fredrik Lundh
fredrik at pythonware.com
Tue Sep 26 06:06:33 EDT 2006
codefire wrote:
> I was just trying to check if objects were the same (object), didn't
> know Integers were a special case.
they're not, really; "is" works the same way for all objects.
when you ask for a new immutable object, a Python implementation may
always reuse an existing object, if it wants to.
the CPython implementation does this for small integers, booleans, None,
empty tuples, certain strings, type objects, etc. this also applies to
library code; for example, string methods often return a reference to
"self" if the method didn't actually change anything.
</F>
More information about the Python-list
mailing list