Multiply operator applied to list(data structure)
问题 I'm reading How to think like a computer scientist which is an introductory text for "Python Programming". I want to clarify the behaviour of multiply operator ( * ) when applied to lists. Consider the function make_matrix def make_matrix(rows, columns): """ >>> make_matrix(4, 2) [[0, 0], [0, 0], [0, 0], [0, 0]] >>> m = make_matrix(4, 2) >>> m[1][1] = 7 >>> m [[0, 0], [0, 7], [0, 0], [0, 0]] """ return [[0] * columns] * rows The actual output is [[0, 7], [0, 7], [0, 7], [0, 7]] The correct