Home > other >  A great god to explain: the same two Python tuple memory address sometimes, sometimes is not the sam
A great god to explain: the same two Python tuple memory address sometimes, sometimes is not the sam

Time:09-27

Until there is a concept: for immutable data types (such as int, float, STR, tuple) is Shared by all objects, which are in the same scope, the same two variables will point to the same object,
But today the validation function parameter passing mechanism, found the same two Python tuple memory address sometimes, sometimes not, don't know is what reason, don't know the great spirit here can you give an explanation.
The first picture is in interactive mode, the second picture is to write the text after the execution of.
 [code=python] [code=python]

CodePudding user response:

Show incomplete problem!

Figure 1 a program you have as a result, no problem,
Do you have as a result, figure 2 light application specific how to write?

CodePudding user response:

Tried really have the building Lord said phenomenon, the individual is understanding and retaining the source file is compiled into byte code, and then execute bytecode made special treatment for a tuple, in the process of element are constants and immutable type, and use the same the same memory, interactive mode without memory storage of the tuple without this processing,

CodePudding user response:

refer to the second floor of ice wind response:
tried really have the phenomenon, the original poster said is personal understanding and retaining the source file is compiled into byte code, and then execute bytecode made special treatment for a tuple, in the process of element are constants and immutable type, and use the same the same memory, interactive mode without memory storage without the processing of the tuple,



Thank you, I also feel and interpreter to memory allocation mechanism, but why only interactive mode problems the tuple, and the numeric and string is no problem,
Don't just because numeric and string type is simpler

CodePudding user response:

Same address references, it is the same ID
  • Related