+ 1
https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list “The reason is that replicating a list with * doesn’t create copies, it only creates references to the existing objects” a[0].append(4) line mutates the object that a[0] currently references to. a[0] = [1] line makes a[0] now references to [1] (a[0] here acts as a lvalue) a[1], a[2]... still reference to the original object.
19th Oct 2021, 4:43 PM
Wei-Ting Yang 🇹🇼