search

Home  >  Q&A  >  body text

Problems with Python3.6 int optimization mechanism, 64-bit machines (-5 to 257)

Optimization mechanism in python (both 2.7 and 3.5):
Numbers between -5~257, if you use the first assignment method, then they still belong to the same memory.
But the test code I wrote on my local machine is as follows:

Result

#This is inconsistent with the above.

Then I tested it on the compiler on the Python official website and it was correct


I would like to ask what is the cause of this. . .

ringa_leeringa_lee2826 days ago819

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-18 10:56:54

    1. It is a py module file. In the same module, the same constant object is only allocated one storage unit

    2. It is a python interpreter. This one has decimal optimization of -5~257

    reply
    0
  • Cancelreply