QuestionQ177

VerifiedData Collections – Tuples, Dictionaries, Lists, and Strings

What output is expected from the following code?

Question Image

Explanation

Assignment of a Python list creates another reference to the same list rather than a copy. The append operation therefore leaves both variables referring to a three-item list, so len(collection) + len(duplicate) evaluates to 3 + 3, or 6.

Community Discussion

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