← 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?
- A.It creates a list of 9 zeros instead of a grid
- B.It raises a TypeError
- C.All three rows are the same list object, so changing one row changes all of them
- 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 →