'Why does python change the value in this list?
So this is my code but I can't understand why python behaves like that
row1 = ['⬜️', '⬜️', '⬜️']
row2 = ['⬜️', '⬜️', '⬜️']
row3 = ['⬜️', '⬜️', '⬜️']
map = [row1, row2, row3]
selectedRow = map[1]
selectedRow = ['X', '⬜️', '⬜️']
for row in map:
print(row)
returns:
['⬜️', '⬜️', '⬜️']
['⬜️', '⬜️', '⬜️']
['⬜️', '⬜️', '⬜️']
but with
selectedRow = map[1]
selectedRow[0] = "X"
returns :
['⬜️', '⬜️', '⬜️']
['X', '⬜️', '⬜️']
['⬜️', '⬜️', '⬜️']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
