By id () function python learning data storage and reference

id () function is built-in functions of the python, the memory address for acquiring object.

1.1

 As can be seen, the address in memory 33 is 19877464, the assignment of a variable store, in fact, is to point to the memory address 33 is stored.

1.2

 Not only are digital type, different strings in the same character actually point to the same memory address

1.3

But the character "3" and 3 digital storage address is not the same

 

 

So, python in the parameters passed to the function is pass by value or address it? It is variable depending on the object or transmitted immutable objects.

2.1 immutable objects

To pass variables to the function actually make a function where the variables point to store digital memory address 3, and the operation of variables within a function, it actually points to become other numbers will not affect variables outside the function x.

 

 

 

 

 2.2 Variable Object

 

Actually passed to the function is the first address list, in function of the value of the list will not affect the variable points to the first address, so the list of elements within the function changes will affect the list of elements outside the function.

 

 

 

Guess you like

Origin www.cnblogs.com/wujiecong/p/11577581.html