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. . .
1、是py模块文件,在同一个模块内,相同的常量对象只分配一个存储单元
2、是python解释器,这个才有-5~257 的小数优化