0

I run an example:

a = 200 + 56
b = 256
c = 200 + 57
d = 257

print('%r == %r: %r' % (a, b, a == b))
print('%r is %r: %r' % (a, b, a is b))
print('%r == %r: %r' % (c, d, c == d))
print('%r is %r: %r' % (c, d, c is d))

# Result:

# 256 == 256: True
# 256 is 256: True
# 257 == 257: True
# 257 is 257: False

Please explain for me, why 257 is 257: False? (while 256 is 256: True)

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • 1
    Additional nice reads: 1) http://stackoverflow.com/questions/13650293/understanding-pythons-is-operator 2) http://stackoverflow.com/questions/34147515/is-operator-behaves-unexpectedly-with-non-cached-integers – Dimitris Fasarakis Hilliard Sep 01 '16 at 14:14
  • 1
    also has an answer [here](http://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is-in-python) – Daniel Lee Sep 01 '16 at 14:16

0 Answers0