You can use this assignment in your class!
Mastery Progress(100.0%)
i

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")Figure A
You answeredJUST NOW

(Student response here)

Did you like this question?

(Voting helps us personalize your learning experience!)
imgInstructor solution
Alec KretchAUG 26, 2022, 4:11:47 PM

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.

Was this helpful?

(Voting helps us personalize your learning experience!)
imgControl Flow in Python Presentation (pages 4, 5)

Was this helpful?

(Voting helps us personalize your learning experience!)
Think you've got it?

What is the output of the code in the updated figure, Figure B?

  • a = ["spam", "ham", "eggs"]
b = ["spam", "ham", "eggs"]
if a == b:
    print("True")
else:
    print("False")Figure B
Select one of the following options:
  • A.

    False

  • B.

    True

Submit answer

Was this helpful?

(Voting helps us personalize your learning experience!)

You may exit out of this review and return later without penalty.