parameter passing:
The argument is passed by automatically assigning the object to the local variable, and the object passed as a parameter is never automatically copied
The assignment of the parameter name inside the function does not affect the caller
Changing the value of a variable object parameter to a function may have an effect on the caller (in essence: immutable objects, such as String simple type tuples) are passed by ' value ', and mutable objects such as dictionary lists are passed through ' pointers '.
>>> def Change (A, B):
a=2
Print ID (b)
Print B
b[0]= ' spam '
Print B
>>> x=1
>>> l=[1,2]
>>> Change (x,l)
27900424
[1, 2]
[' Spam ', 2]
>>> b
Traceback (most recent):
File "<pyshell#87>", line 1, in <module>
B
Nameerror:name ' B ' is not defined
>>> ID (L)
27900424
>>>
b is a local variable name, but it is passed to a Mutable object, because the second assignment is the change of the object that occurred in the same place, the result of assigning the value of b[0 in the function will affect the value of L after the function returns, in fact we have not modified B, we have modified the part of the object that B is currently referencing. And this change will affect the caller
Python function parameter passing