$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #194

What is the output?

x = [[0] * 2] * 2
x[0][0] = 9
print(x)
  1. [[9, 0], [9, 0]]
  2. [[9, 0], [0, 0]]
  3. [[9, 9], [0, 0]]
  4. Error
The outer multiplication copies the reference, so both rows are the same inner list.
Play Problem Solving ▸