← Quiz: Matrix Traversal: all 13 questions
Quiz: Matrix Traversal · Question 5 of 13
What does this print? (code)
What does this print?
grid = [[0] * 3] * 2
grid[0][0] = 9
print(grid)
- A.[[9, 0, 0], [0, 0, 0]]
- B.[[9, 0, 0], [9, 0, 0]]
- C.[[9, 9, 9], [0, 0, 0]]
- D.Error
Answer & explanation
Correct answer: [[9, 0, 0], [9, 0, 0]]
Both rows are the same list object, so changing one changes "both". Build rows with a comprehension.
Can you get the rest right without peeking?
Take the timed Quiz: Matrix Traversal quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →