Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Strange behavior of lists in python [duplicate]

$
0
0

I don't understand this behavior of lists in Python:

>>> a1 = [[0,0],[0,0]]>>> a2 = [[0]*2]*2>>> a1[[0, 0], [0, 0]]>>> a2[[0, 0], [0, 0]]>>> a1[0][0] = 1>>> a2[0][0] = 1>>> a1[[1, 0], [0, 0]]>>> a2[[1, 0], [1, 0]]

Why does assignment of one element affect another element?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>