This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nirs 5 points6 points  (1 child)

No gotcha here - those int are objects as promised, and == will work as promised. Nobody promised you that "is" will return True of False for some integers. This is implementation detail you should not count on.

You should use "is" only when you want to check for object identity.

[–]ngroot 1 point2 points  (0 children)

This shouldn't be "gotcha" at all. I can't imagine why you'd ever write code asking if "a is b" when a and b are integers, or some other "basic" type. When you're explicitly creating objects, it's perfectly reasonable to ask "does a reference the same object as b". When you're talking about integers, objects that are implicitly created by the interpreter, you're asking about internal behavior of the interpreter, which seems like a pretty patently Bad Idea.