(e-mail address removed) a écrit :
Sorry about removing my message, I posted with the wrong google
account, I don't really want my email where those irritating spam bots
can find it.
I immediately thought of is, and tested it in the console, but it
didn't work quite like I expected:
True
clearly foo and bar have the same value but they are different objects
aren't they?
Nope. They are two different names bound to the same integer object. You
may have similar situation with strings:
True
This is an application of the lightweight pattern. The Python
interpreter reuse the same "value object" to avoid memory clutter. Since
ints and strings are immutable, this is perfectly safe (but yet
confusing when you're not aware of this).
Yet applying the is operator yields True.
Yes. But now you know why !-)
And don't worry, this is quite unlikely that it will cause you any
trouble in real code.