For Python values. I encountered a problem today, abstracted as the test I code below
1: #!/usr/bin/python2.6
2:
3: def FuncTest1(str_list):
4: path = '/home/test/file'
5: str_list = path.split('/')
6:
7: def FuncTest2(str_list):
8: path = '/home/test/file'
9: str_list.extend(path.split('/'))
10:
11:
12: str_list = []
13: FuncTest1(str_list)
14: print 'FuncTest1: %s' % str_list
15: str_list = []
16: FuncTest2(str_list)
17: print 'FuncTest2:%s' % str_list
That is, whether to pass the value or reference the test parameter.
The test result is:
In this analysis, the python parameters are passed with values. For a simple type, it refers to the reference (or pointer) of an object that is passed for a complex type or object ).
Therefore, for the above situation,
In functest1, the passed str_list points to a new result. It can be considered that the point of the temporary object is modified in the function. The external function remains unchanged.
In functest2, a method call is executed for str_list, and its modification is valid for incoming requests.
This is similar to Java.