>>> a = 300
>>> b = 300
>>> a is b
False
>>> a = 100
>>> b = 100
>>> a is b
True
>>>
CPython has a small set of canonical objects for integers.I once ran into a bug which had been there for years, since some Integer values had never crept over that magic limit, and auto-boxing allowed the numbers to be treated as int's all over, so it really took me some time to figure out what was going on...
This right here is why it's critical to have developers of all levels across a team. Those of use who have been doing this long enough don't remember what caused us issues as juniors. We need the mid-levels to translate and remind us of these things lol
They are both objects; they only differ in size.
>>> a = "this is a long sentence in a string literal"
>>> b = "this is a long" + " sentence in a " + "string literal"
>>> a is b
False
>>> id(a)
4386376272
>>> id(b)
4387721264
>>> a == b
TrueIf you test at the shell it apparently misses it (though it works for smaller strings e.g. "abc" / "a" + "b" + "c"), but if you put the same thing in a file and run it, it'll tell you the two strings are identical.