Apr-02-2022, 08:45 PM
I try to create a copy of list via two ways:
a = [[1,2, 3], [4, 5, 6], [7, 8, 9]] b = a.copy() b[0].pop(2) b[1].pop(2) b[2].pop(2)
a = [[1,2, 3], [4, 5, 6], [7, 8, 9]] b = [] for i in a: b.append(i) b[0].pop(2) b[1].pop(2) b[2].pop(2)
a
Output:[[1, 2], [4, 5], [7, 8]]
b
Output:[[1, 2], [4, 5], [7, 8]]
I consider 'b' is a new list, all of operation on 'b' not should be affect original list 'a', the Python document seems not more description for this, someone can explain? or that's a bug?