Python may optimize small read-only objects (strings, numbers, tuples) by "interning" them (keeping a list of common small objects), or noticing they are the same at compile-time and not making a second copy.
Since these objects can not be changed, this is a safe optimization, and can result in is
returning True for two objects that would otherwise be separate.
The actual specifics are version specific and can change from release to release. They are certainly equals (==
) , but may or may not be the same (is
).
Lists can be modified (they are mutable
), therefore, under the current language rules, they have to be viewed as different objects. They have separate identify and are not is
the same. Otherwise changing c
would change d
.