def testf(st):
st=st[1:]
print st
def popf(st):
st.pop(0)
print st
a = ["response", ["wis", "hello"], ["deng", "shen"]]
testf(a)
print a
a = ["response", ["wis", "hello"], ["deng", "shen"]]
popf(a)
print a
下面困惑是輸出:蟒蛇:使用函數刪除列表元素,不然我和結果
[['wis', 'hello'], ['deng', 'shen']]
['response', ['wis', 'hello'], ['deng', 'shen']]
[['wis', 'hello'], ['deng', 'shen']]
[['wis', 'hello'], ['deng', 'shen']]
我想用一個函數來刪除列表元素,但我m困惑爲什麼功能testf()
不能刪除功能後的元素,但功能可以做到。有什麼不同?如果不在該功能中,st=st[1:] = st.pop(0)
(del st[0]
也有效)。