QuestionQ58

VerifiedData Structures

What is the output when the following is run in a Python shell?

Question Image

Explanation

list() performs a shallow copy of the outer list, so both lists refer to the same nested lists. Mutating the first nested list by appending 2.5 is therefore reflected in listoflists, whereas adding [5, 6] changes only the copied outer list.

Community Discussion

No comments yet. Be the first to start the discussion!