What is the output of the following Python code snippet?
m = [[0] * 2] * 2
m[0][0] = 1
print(m)
m[0][0] = 1
print(m)
Correct answer
B. [[1, 0], [1, 0]]
6 views
B. [[1, 0], [1, 0]]
6 views
Both rows reference the same inner list, so the change shows in both.
Asked in: Python Interview Lists
https://docs.python.org/3/tutorial/datastructures.htmlNot sure why the answer is B? Ask here and get an explanation.