LearnFrenzy
Sign in Take a free test

Variables and Data Types · Predict the Output · Question 9

Two names, one list Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the output of the following Python program?

main.py
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links