2 + 2 = 5
Laszlo Nagy
gandalf at shopzeus.com
Thu Jul 5 10:34:22 EDT 2012
On 2012-07-04 21:37, Paul Rubin wrote:
> I just came across this (https://gist.github.com/1208215):
>
> import sys
> import ctypes
> pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
> five = ctypes.cast(id(5), pyint_p)
> print(2 + 2 == 5) # False
> five.contents[five.contents[:].index(5)] = 4
> print(2 + 2 == 5) # True (must be sufficiently large values of 2 there...)
>
> Heh. The author is apparently anonymous, I guess for good reason.
>>> five.contents[five.contents[:].index(5)] = 4
>>> 5
4
>>> 5 is 4
True
But this I don't understand:
>>> 5+0
4
>>> 5+1
4
>>> 5+2
6
More information about the Python-list
mailing list