Python Array Strange Behavior?
Can anyone explain why is this happening? Case 1: >>> a = [[0]] *3 >>> print a [[0], [0], [0]] >>> a[1].append(0) >>> print a [[0, 0], [0, 0], [
Solution 1:
In the first case, the three elements in a
actually reference to the same list objects. You can check their id:
>>>id(a[0])
4524132472
>>>id(a[1])
4524132472
>>>id(a[2])
4524132472
Post a Comment for "Python Array Strange Behavior?"