If I want to change a variable value from within a function I believe I have two options: a) Directly modify the parameter: x=[1,2,3] def add4tolist(inputlist): inputlist.append(4) add4tolist(x) x [1,2,3,4] b) Return the result, keeping the passed parameter untouched: x=[1,2,3] def add4tolist(inputlist): return (inputlist[:]).append(4) x=add4tolist(x) x [1,2,3,4] a) is simpler, however, it only works on immutable type b) is more general, however, you still have to be careful about accidently modifying mutable parameters. Is there any accepted programming etiquette on how to best go about this? 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