Call a colleague's function, pass in the goods_list, get the product information, and then match the product information with the Goods_list information to merge.
But the colleague returned the data and changed the parameters I passed in, Goods_list. Equivalent to a parameter reference, that is, changing data at the same address in memory,
Overwrite the parameter goods_list I passed in. Cause my parameters to not match.
This is hereby recorded:
Let's look at an example.
T_list = [1, 2]
T_dict = {"A": "Haha", "B": "Hehe"}
T_STR = "123"
def test_list (param):
Param[0] = 3
return param
def test_dict (param):
Param["a"] = "Lala"
return param
def test_string (param):
param = "456"
return param
If __name__== "__main__":
Print "==test list=%s"%test_list (t_list)
Print "==test list=%s"%t_list
Print "################################"
Print "==test dict=%s"%test_dict (t_dict)
Print "==test dict=%s"%t_dict
Print "################################"
Print "==test str=%s"%test_string (T_STR)
Print "==test str=%s"%t_str
The return data is as follows
return value ==test list=[3, 2]
Original Value ==test list=[3, 2]
################################
return value ==test dict={' a ': ' Lala ', ' B ': ' Hehe '}
Original value ==test dict={' a ': ' Lala ', ' B ': ' Hehe '}
################################
return value ==test str=456
Original Value ==test str=123
Unlike other languages, Python does not allow programmers to choose whether to pass a value or pass a reference when passing parameters. Python parameter passing is definitely a way to "pass an object reference". In fact, this approach is equivalent to a synthesis of value-passing and reference. If a 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 reference". If a function receives a reference to an immutable object (such as a number, character, or tuple), it cannot directly modify the original object-the equivalent of passing the object through a "pass value".
Calling the pit--------a colleague function throws a Python value reference and a reference to a parameter