I know the is
operator in Python has an unexpected behavior on immutable objects like integers and strings. See "is" operator behaves unexpectedly with integers
>>> a = 0
>>> b = 0
>>> a is b
True # Unexpected, we assigned b independently from a
When it comes to mutable objects, are we guaranteed that two variables expected (as written in the code) to reference two distinct objects (with equal value), will not be internally bound to the same object ? (Until we mutate one of the two variables, then of course the references will differ.)
>>> a = [0]
>>> b = [0]
>>> a is b
# Is False guaranteed ?
Put in other words, if somewhere x is y
returns True
(x
and y
being mutable objects), are we guaranteed that mutating x
will mutate y
as well ?