def myfunc(x): y = x y.append('How do I stop Python from modifying x here?') return y x = [] z = myfunc(x) print(x)
You do:
y = x[:]
to make a copy of the list x.
x
You need to copy X before changing it,
def myfunc(x): y = list(x) y.append('How do I stop Python from modifying x here?') return y x = [] z = myfunc(x) print(x)
Source: https://habr.com/ru/post/1753024/More articles:Reporting, such as income / loss, etc. - sqlHow to add ssh key to connect to git? - gitsafe random numbers in asp.net - securityCaching Design for Medium / Small Web Application? - javascriptIs it possible to use asp: Button like Html.ActionLink? - asp.netproblem using MPMovieController in iPhone SDK 4.0 - objective-cUsing array_key_exists with preg_match - arraysReused jquery ajax queries - jqueryWhat is the difference between a .h (header file) and a .cpp file? - c ++Is this a valid jquery callback function call? - functionAll Articles