You are true for the lists.
For the integer parts, the Language Reference Manual says that it is an implementation detail:
after a = 1; b = 1, a and b may or may not refer to the same object with the value one, depending on the implementation
In the CPython reference implementation, a is b
is true, because:
The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object.
For integers outside of the cached range, il may depend on whether you are in immediate or compiled mode: if Python can see a full module at once, it may use optimization to have a
and b
refere to to same object it is does not change the behaviour. But as those are only implementation detail you should never rely on two identifiers sharing or not the same object for non reference type.