What's the output of the code in Figure A?
![a = ["spam", "ham", "eggs"]
b = ["spam", "ham", "eggs"]
if a is b:
print("True")
else:
print("False")](/files/5ffe289c8fa4e8b2b96dbad2.png)
Instructor solution
False
--
The is
operator compares instances in memory. Even though the values of a
and b
are the same, since lists are mutable (meaning, they can be modified without being entirely recreated), a
and b
point to different places in memory.
Control Flow in Python Presentation (pages 4, 5)
You may exit out of this review and return later without penalty.