What is the output of the following Python code and why? a = [1, 2, 3]; b = a; c = list(a); b[2] = 100; print(a == b, a is b, a is c, a)
1Times asked
Nov 2026Last seen
Nov 2026First seen
π‘ Model Answer
Here a is a list [1, 2, 3]. b = a makes b reference the same list object. c = list(a) creates a shallow copy, a new list with the same elements. The assignment b[2] = 100 mutates the shared list, so a also changes to [1, 2, 100]. The comparisons give: a == b is True because the contents are equal; a is b is True because they are the same object; a is c is False because c is a different list object. The final printed list is [1, 2, 100].
This answer was generated by AI for study purposes. Use it as a starting point β personalize it with your own experience.
π€ Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI β Starts at βΉ500