Question 3
Back to Exercise
What is the output of the following Python program?
class Team:
members = []
def add(self, name):
self.members.append(name)
t1, t2 = Team(), Team()
t1.add("Asha")
t2.add("Ravi")
print(t1.members, t2.members is t1.members)
- A ['Asha'] False
- B ['Asha'] True
- C ['Ravi'] False
- D ['Asha', 'Ravi'] True Correct
Correct Answer: Option D
Both objects mutate the single list stored on the class.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!