Skip to content
Onsite

Output: [[0] * 3] * 3, then assign one cell

EasyP2Output

What does this code print?

1grid = [[0] * 3] * 3
2grid[0][0] = 1
3print(grid)
4
5good = [[0] * 3 for _ in range(3)]
6good[0][0] = 1
7print(good)
Saved automatically

One line per print, as Python prints it. An uncaught exception as its last traceback line, for example ZeroDivisionError: division by zero.

Hints

Saved automatically