0

I have 2 variables in python as mentioned below and both have same integer values

>>> a = 256 

>>> b = 256

When I compare them, I get True as mentioned below

>>> a is b 

True

but again when I compare other 2 equal variables I get false

    c = 257
    
    d = 257
    
    c is d
    
    False

Is there any problem in python Interpreter?

I didn't understood the logic behind it

  • 2
    Do not use `is` to compare things for equality. `is` does not look at value. It asks, "are these two things the same object?", and with small integers there is no guarantee that "200" right now will be the same object as "200" 3 minutes from now. Use `==`. – Tim Roberts Dec 13 '22 at 01:11
  • Another duplicate is ["is" operator behaves unexpectedly with integers](https://stackoverflow.com/q/306313/4996248). It features the same 256 vs. 257 behavior. – John Coleman Dec 13 '22 at 01:19

0 Answers0