0

My code is:

x = 1000
y = x + 0
z = 1000

print(x is y, x is z, y is z)

In REPL mode I have next result:

>>> False False False

But if I run script in script mode (like '1.py' for example) I have next result.

>>> False True False

Similar result in REPL with

>>> x = 1000; y = x + 0; z = 1000
>>> print(x is y, x is z, y is z)
False True False

I think that lexical analyzer make object optimization by translate my code to bite code. But I can't find desciption this process in documentation or books.

Where can I learn this material?

UPD: I need description in official notes. Like python.org. How to work AST-analizer optimization for example.

UPD2: It is desirable without the need to study the CPython source code in depth.

Eugene
  • 345
  • 1
  • 7
  • Does this answer your question? [What's with the integer cache maintained by the interpreter?](https://stackoverflow.com/questions/15171695/whats-with-the-integer-cache-maintained-by-the-interpreter) – ssp Aug 02 '22 at 06:37
  • @ssp by your link that problem is disscused. I find description in sources like python.org. With description not only by C-code. For AST optimizer I guessed earlier. – Eugene Aug 02 '22 at 08:45

0 Answers0