Hi all, I (possibly incorrectly) thought that parameters passed in functions were modifiable by default in Python, here is some code that I tested with: >>> x=[1,2,3] >>> def paramtest(parameter): ... print "parameter =",parameter ... print "parameter ID =",id(parameter) ... parameter.append("hello") ... print "new parameter =",parameter ... print "new parameter ID =",id(parameter) ... parameter=[2,4,6,8] ... print "modified parameter =",parameter ... print "modified parameter ID =",id(parameter) ... >>> paramtest(x) parameter = [1, 2, 3] parameter ID = 20270396 new parameter = [1, 2, 3, 'hello'] new parameter ID = 20270396 modified parameter = [2, 4, 6, 8] modified parameter ID = 20263708 >>> x [1, 2, 3, 'hello'] It looks like "parameter=[2,4,6,8]" creates a new local variable that overrides the passed parameter. How do I do this properly so that the passed parameter changes in all parameter type cases? Thanks, z. Regards, zzzzz. ---------------------
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4