I wrote a blog post about this in the past. It's really fun going through the oddities of the language like this.
It caches small integers, but also literals used in the same interpreter context (I'm probably getting that last term wrong). You'll get different results if you run these in from the shell as opposed to executing a script, try it out!
Here's a fun example
>>> x = 256; x is 256
True
>>> x = 257; x is 257
True
>>> x = 257
>>> x is 257
False
>>> def wat():
... x = 500
... return x is 500
>>> wat()
True
It caches small integers, but also literals used in the same interpreter context (I'm probably getting that last term wrong). You'll get different results if you run these in from the shell as opposed to executing a script, try it out!
Here's a fun example