1
我之前已經問過這個問題了,但是修正不適用於x = [[]],我猜是因爲它是一個嵌套列表,這是我將要處理的內容。如何阻止Python函數修改其輸入?
def myfunc(w):
y = w[:]
y[0].append('What do I need to do to get this to work here?')
y[0].append('When I search for the manual, I get pointed to python.org, but I can\'t find the answer there.')
return y
x = [[]]
z = myfunc(x)
print(x)
請參閱http://stackoverflow.com/questions/2541865 – jweyrich 2010-07-04 06:06:32
重複:http://stackoverflow.com/questions/845110/emulating-pass-by-value-behaviour-in-python – ChristopheD 2010-07-04 06:18:08