QuestionQ226

VerifiedData Collections – Tuples, Dictionaries, Lists, and Strings

What is the expected output of this code?

Question Image

Explanation

Separate list literals produce different objects, so their identities differ even though their values are equal. The is not operator tests object identity, while != tests value inequality. Assigning list2 to list1 makes both variables refer to the same list.

Community Discussion

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