0

I'm digging into Python and encounters a weird result when using is statement.

The initial statement :

is will return True if two variables point to the same object.

My test case :

#_________
# 1st case
#_________
a = 256
b = 256
a is b
>>> True

#________
#2nd case
#________
a = 257 
b = 257 
a is b
>>> False

#________
#3rd case
#________
a = 257; b = 257;
a is b 
>>> True

Question :

1. Why, in the second case, a and b are not the same object while they are the same in the first one ? 2. Why they a and b are the same in 3rd statement but not in the 2nd ?

Thanks in advance for enlighten me.

iFlo
  • 1,442
  • 10
  • 19

0 Answers0