hi I make a list in list and append in [0] index a value. but it appends in all index. can andybody know why?
code:
code:
code:
matrix=[[1]]*3 print(matrix) matrix[0].append(2) print(matrix)output:
Output:[[1], [1], [1]]
[[1, 2], [1, 2], [1, 2]]
if I try in this way I get this outputcode:
matrix=[] for i in range(3): ++++list=[1] ++++matrix.append(list) print(matrix) matrix[0].append(2) print(matrix)output:
Output:[[1], [1], [1]]
[[1, 2], [1], [1]]
why difference beetwen two output? thanks.