Variables in Python are treated as references to objects. When a Python function call passes a parameter, the programmer is not allowed to choose whether to pass a value or to pass a reference, and the Python parameter is passed in the way of "object reference".
This is equivalent to the combination of a value and a reference, and if the function receives a reference to a mutable object (such as a dictionary or a list), it can modify the original value of the object-the equivalent of passing the object through a "pass-through", if the function receives an immutable object (such as a number, string, or tuple), you cannot directly modify the original object-the equivalent of a "pass value" to pass the object.
def Func (x): x = 20a = 10Func (a) print (a) #输出10, when Func (a) is called, the x variable inside the func points to an integer object 10,# (that is, a reference to integer object 10). In the Func internal attempt to modify an immutable object, #会使得Func内部的x指向一个新的对象20, while the external variable a still points to the immutable object 10.def FUNC2 (x): x[0] = 20a = [1,2,3]func2[a]print (a) #结果为 [20, 2, 3].
Python General internal assignment variables, is a reference variable, and the C language is similar to the concept of the transfer address. The memory address of X can be queried by ID (x).
If a=b, the address of A and B is the same; if you just want to copy it, use a = b[:]
Python's variable passing