I launch the same program in Visual Studio or Anaconda:

a = 777 b = 777 print('a is b ? ', a is b) #должно быть False print('a == b ? ', a == b) print( 'id(a)' ,id(a)) print( 'id(b)' ,id(b)) 

I get True True and the same id. The result of the work does not match the description of the Python language in the standard. Then I type the same code in the console and get the correct result:

False True and different id.

What is the secret of a buried dog?

  • Simply you are still @ Young :) :) Sorry, I could not resist :) I think the fact is that when you started the console, or rather an interactive mode in which each command is executed line by line, the 777 constant caching did not occur because of what a new was created on each assignment object with reference to 777 . And when you started the .py file, the interpreter optimized the code by doing that caching - gil9red
  • What's up with Integer cache inside Python? stackoverflow.com/questions/15171695/… - S. Nick
  • Instead of two separate lines, type in the console a=777;b=777 in one line - and you also get True. Nobody forbids the interpreter to combine the same numbers into one object - andreymal
  • At the expense of caching, I understand everything. And I also understood the explanations. (written is available!). It turns out that in command mode (console), each command is launched and launched as a separate "program" and therefore no caching occurs. Right? - Young still
  • Executed the code a = 777 in the console; b = 777 and print (a is b) received in the answer False. Something is wrong in the "Danish kingdom" ... - Young still

0