首先,對於不好的標題感到抱歉。我不知道如何來形容這個問題:列表值問題
a = 1
b = 2
c = 3
aa = 0
bb = 0
cc= 0
list = [[1, a] ,[2, b] ,[3 ,c]]
print(list)
secondList = [aa, bb, cc]
x = -1
for item in list:
x=x+1
if list[x][1] == a:
print(aa, "aa")
secondList[x] = secondList[x] + 1
print(aa , "aa")
print(x, "x")
print(secondList[x], "SecondList[x]")
secondList = [aa, bb, cc]
print(secondList)
我想到:
[[1, 1], [2, 2], [3, 3]]
0 aa
1 aa
0 x
1 SecondList[x]
[1, 0, 0]
而是我得到:
[[1, 1], [2, 2], [3, 3]]
0 aa
0 aa
0 x
1 SecondList[x]
[0, 0, 0]
爲什麼AA的值不改變我的時候打印它或secondList,但是當我打印secondList [x]?
評論不適用於擴展討論;這個談話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/94365/discussion-on-answer-by-willywonka-dailyblah-list-value-issue)。 –