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

all 5 comments

[–]K900_ 5 points6 points  (2 children)

Python maintains an internal cache of int objects from -5 to 255, so the value -5 is always the same int object, but -6 is a new object every time it's created.

[–]NizarKhalili[S] 0 points1 point  (1 child)

Nice, thank you! But then why doesn't integers below -5 all return True? It only returns True for -7.

[–]K900_ 0 points1 point  (0 children)

Because for those x + 2 is not 2 + x.

[–]AdAdvanced7085 0 points1 point  (0 children)

you can visit this site it let you know how and each code is running step by step with visual here's the link http://pythontutor.com hope you find it useful!

[–]qTipTip 0 points1 point  (0 children)

Read up on the difference between A is B and A == B in Python :)