Question 9
Back to Exercise
What is the output of the following Python program?
a = [1, 2]
b = a
b.append(3)
c = [1, 2, 3]
print(a, a is b, a == c, a is c)
- A [1, 2] True True False
- B [1, 2, 3] True True False Correct
- C [1, 2, 3] True True True
- D [1, 2] False False False
Correct Answer: Option B
b is another name for a, so append changes the one shared list. c has equal contents but is a different object.
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!