我遇到了一個我無法解釋的錯誤。以下是代碼:'int'對象不能迭代列表列表
board = [[1, 2, 3],[1, 2, 3],[1, 2, 3]]
col = 0
col_nums = []
for rows in board:
col_nums += rows[col]
這給出'int'對象不是可迭代錯誤。 這工作雖然:
for rows in board:
print(rows[col])
我想col_nums = [1, 1, 1]
結束。它似乎並沒有迭代任何整數,只是rows
,這是一個列表。我認爲這可能與+=
有關。
我很驚訝,我沒有看到這一點。謝謝 – qwr