LearnFrenzy
Sign in Take a free test

OOP in Python · OOP in Python MCQ · Question 5

__str__ versus __repr__ Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

Which method does print([p]) use to show the object p inside the list?

  • A __str__
  • B __repr__ Correct
  • C __format__
  • D __print__
Correct Answer: Option B

Containers show their items with repr(); print(p) on its own uses __str__.

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