Terry Reedy wrote:
What immutability has to do with identity is that 'two' immutable objects with the same value *may* actually be the same object, *depending on the particular version of a particular implementation*.


t1 = (1,2,3) # an immutable object
t2 = (1,2,3) # another immutable object

Whether or not this is 'another' object or the same object is irrelevant for all purposes except identity checking. It is completely up to the interpreter.

t1 is t2
False

In this case, but it could have been True.

t1 == t2
True

A more telling example:
>>> t1 = (1, 2) + (3,) # an immutable object
>>> t2 = (1,) + (2, 3) # another immutable object
>>> t1 is t2
>> False
>>>>> t1 is t2
>> False

Here you make obvious that (assuming an optimizer that
is not far more aggressive than Python is used to), in
order to make equal immutable values identical, you'd
have to end each operation producing an immutable result
with a search of all appropriately typed values for one
that was equal.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to