-2
a = 10 # range -5 to 256
b = 10 # range -5 to 256
print(id(a))
print(id(b))
print(a is b)

# OK THAT'S FINE 

BUT

a = 10 # range -5 to 256
b = 10 # range -5 to 256
print(id(a))
print(id(b)) # same memory adress
print(a is b)

# That's working

c = 3 # range -5 to 256
d = 5 # range -5 to 256
print(id(c))
print(id(d)) 
print(c is d) 

NOT same memory adress O_o False because... meeeehhh the range should be fine !

martineau
  • 119,623
  • 25
  • 170
  • 301
nighthaven
  • 21
  • 4

1 Answers1

1

With the following illustration, you should understand why:

  • a is b is True
  • c is d is False

for the number between -5 and 256

and why:

  • e is f is False

for other numbers outside of this special range

enter image description here

Corralien
  • 109,409
  • 8
  • 28
  • 52
  • documentation i follow : PyObject *PyLong_FromLong(long v) Return value: New reference. Part of the Stable ABI. Return a new PyLongObject object from v, or NULL on failure. https://docs.python.org/3/c-api/long.html?highlight=pylongobject#c.PyLongObject Corralien, according to your help, this compare the value. but is should compare the id no? unless between -5 and 256 the id will be the same only if the value is the same and after the id will be different whatever the result ? will try... – nighthaven Feb 16 '22 at 22:11
  • Ok i think i understand, you were right Corralien ! – nighthaven Feb 16 '22 at 22:17