If I fire a terminal with Python and I write:
>>> x = 100
>>> x == 100
True
>>> x is 100
True
I can easily see that the boolean works perfectly for both ==
and is
But if I try to set 1000
as variable as result I have:
>>> x = 1000
>>> x == 1000
True
>>> x is 1000
False
Is there a way for me to see how the variable is stored on the memory bit by bit? I don't want the memory pointers, I would like to see the 0
and the 1
to see what Python is storing exactly.
- 100 in decimal = 01100100 in binary (8 bits = 1 octet)
- 1000 in decimal = 0000001111101000 in binary (16 bits = 2 octets).
100 fits in a 8 bits octet while 1000 cannot fit into it.
From my understanding ==
always gives a TRUE
because it is reading a value while is
is reading a memory space, so eventually it is reading just the first 8 bits of the octet.