Date: 2008-11-21 08:07:00
Tags: python
stupid python
Lest you be under the impression that I only bash Perl, check out the following oddity in Python: The "is" operator behaves unexpectedly with integers.
"[...] So it should be possible to change the value of 1."

... only if integer objects are mutable. Which they aren't.
Only if you're writing C code that interfaces with Python's API, in which case it's kind of like having root on unix.
Looks like == is the solution but yeah that is really weird. Anyways, you know me, I'm happy to bash any scripting language basically.
Eh, you get the same weird issues in Java.

String a = "Hello, World!"
String b = "Hello, World!"

String c = new StringBuilder().append("Hello, ").append("World!").toString();

assert(a == b); // These strings are interned.
assert(a != c); // c isn't.
Yeah, "is" is used for checking object identity. And it is returning the correct values for integers... it just so happens that some integers are "interned" and some aren't. But why would you need to check the identity of your integers anyway?

I wanted to check the identity of objects, not knowing in advance whether they are numbers or not.

I was in the middle of implementing eqv? from Scheme when I ran into this.
"It depends on what the meaning of 'is' is." :)

Why in heck is there an "is" operator?

Python "is" is equivalent to Java "==".
Python "==" is equivalent to Java ".equals()".

Roughly. I think.
*clings to the security of his language with referential transparency*

Greg Hewgill <>