🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: References and Copying: all 10 questions

Quiz: References and Copying · Question 7 of 10

Why does grid = [[0] 3] 3 cause problems?

Why does grid = [[0] * 3] * 3 cause problems?

  1. A.It creates a list of 9 zeros instead of a grid
  2. B.It raises a TypeError
  3. C.All three rows are the same list object, so changing one row changes all of them
  4. D.The zeros become strings
Answer & explanation

Correct answer: All three rows are the same list object, so changing one row changes all of them

The outer * 3 repeats the reference to one row. Use a comprehension to make separate rows.

Can you get the rest right without peeking?

Take the timed Quiz: References and Copying quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →