0

In python when we are assigning the same integer to two different variables, then why I am getting error number greater than 256.

Why This is True -

a = 256
b = 256

a is b

Why This is False -

a = 300
b = 300

a is b
graj499
  • 87
  • 2
  • 12
  • Your case is found in the accepted answer: "In your case, the second test [which is thie first in this question] only works because Python caches small integer objects, which is an implementation detail. For larger integers, this does not work:" – Nico Haase Sep 14 '22 at 06:49
  • In the second condition you will also get `true`. It doesn't matter either it is 256 or 300. – debugger Sep 14 '22 at 06:50
  • @debugger no, you will get `False`. See Nico Haase comment / duplicate question for more details. – Clément Baconnier Sep 14 '22 at 06:56
  • But I just tried it in an online compiler. How amazing I got true for both – debugger Sep 14 '22 at 07:00
  • @debugger maybe that "online compiler" does not handle this properly? – Nico Haase Sep 14 '22 at 07:11

0 Answers0