2 + 2 = 5

Hans Mulder hansmu at xs4all.nl
Thu Jul 5 14:40:54 EDT 2012


On 5/07/12 19:03:57, Alexander Blinne wrote:
> On 05.07.2012 16:34, Laszlo Nagy wrote:
>>>>> five.contents[five.contents[:].index(5)] = 4
>>>>> 5
>> 4
>>>>> 5 is 4
>> True

> That's surprising, because even after changing 5 to 4 both objects still
> have different id()s (tested on Py2.7), so 5 is 4 /should/ still be
> False (But isn't on my 2.7). But that's some implementation detail we
> are not supposed to play with ;)

On my 2.7, id(5) gives the same value as id(4) == id(2+2), but id(2+3)
has a different value.  The 'is' operator is consistent with 'id':

>>> 4 is 5
True
>>> 2+2 is 2+3
False

This is when using the interactive interpreter; it may be different
in Idle.

-- HansM





More information about the Python-list mailing list