2 + 2 = 5

Alexander Blinne news at blinne.net
Thu Jul 5 19:03:57 CEST 2012


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 ;)

> But this I don't understand:
> 
>>>> 5+0
> 4
>>>> 5+1
> 4
>>>> 5+2
> 6

That's easy:

5+0 is actually 4+0, because 5 == 4, so 5+0 gives 4.
5+1 is actually 4+1, which is 5, but 5 is again 4.
5+2 is 4+2 which is 6.

Greetings




More information about the Python-list mailing list