What other languages use the same data model as Python?

Ian Kelly ian.g.kelly at gmail.com
Thu May 5 12:44:39 EDT 2011


On Thu, May 5, 2011 at 9:41 AM, John Nagle <nagle at animats.com> wrote:
> On 5/5/2011 3:06 AM, Gregory Ewing wrote:
>>
>> John Nagle wrote:
>>
>>> A reasonable compromise would be that "is" is treated as "==" on
>>> immutable objects.
>>
>> That wouldn't work for tuples, which can contain references
>> to other objects that are not immutable.
>
>    Such tuples are still identical, even if they
> contain identical references to immutable objects.

>>> a = (1, 2, [3, 4, 5])
>>> b = (1, 2, [3, 4, 5])
>>> a == b
True
>>> a is b  # Using the proposed definition
True
>>> a[0] is b[0]
True
>>> a[1] is b[1]
True
>>> a[2] is b[2]
False
>>> a[2].append(6)
>>> a
(1, 2, [3, 4, 5, 6])
>>> b
(1, 2, [3, 4, 5])
>>> a == b
False
>>> a is b
False

Thus a and b cannot be used interchangeably even though "a is b"
originally returned True.



More information about the Python-list mailing list