'is compare id but id should be the same between -5 and 256, how come it's not if x = 3 and y = 5? [duplicate]

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 !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source