Indeed ! But it's weird that 123456789 is 123456789 = True, isn't it ? As if Python answers True for a is b if "a is the same as b" before testing if they are the same. Is there a reason for that ?
(123456789+0) is 123456789 = False
but 123456789 is 123456789 = True
Optimizer gets better and better. In 3.7, even 123456788+1 is 123456789 gives True. It's simply that Python realizes it can evaluate constant pure expressions before compiling to bytecode. And it folds constants, of course.
>>> compile('123456788+1 is 123456789', '', 'eval').co_consts
You'll notice there's only one 123456789 there, not two. And there are no 123456788 nor 1.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I tried 158896587456 is 158896587456 on Python 3.6.1 and it answers True :/
(Even with huge numbers it does answer True)
Sorry, this is true when (at least) one of them is stored into a variable:
Indeed ! But it's weird that 123456789 is 123456789 = True, isn't it ? As if Python answers True for a is b if "a is the same as b" before testing if they are the same. Is there a reason for that ?
(123456789+0) is 123456789 = False
but 123456789 is 123456789 = True
Anyway thanks for the example and the answer !
Optimizer gets better and better. In 3.7, even 123456788+1 is 123456789 gives True. It's simply that Python realizes it can evaluate constant pure expressions before compiling to bytecode. And it folds constants, of course.
>>> compile('123456788+1 is 123456789', '', 'eval').co_consts
You'll notice there's only one 123456789 there, not two. And there are no 123456788 nor 1.