0
Question on list in python. Why this output?
A = [ [ ] ] * 3 A[0]. append(3) print(A) Why it prints [[3],[3],[3]] and why not [[3], [ ], [ ] ]
1 Antwort
+ 4
Because when using times 3,
it copies the reference to the empty list
So A == [[], [], []]
but A[0] == A[1] == A[2]
So when you change any one, the same is reflected in the other two, because they are referencing the same list.
https://code.sololearn.com/cDNDoUBxcniR/?ref=app