🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Magic Methods and Properties: all 10 questions

Quiz: Magic Methods and Properties · Question 3 of 10

If a class defines only repr, what does print(obj) use?

If a class defines only __repr__, what does print(obj) use?

  1. A.The default <object at 0x...> text
  2. B.repr, because str falls back to it
  3. C.Nothing; it raises an error
  4. D.The class name only
Answer & explanation

Correct answer: repr, because str falls back to it

The default str calls repr.

Can you get the rest right without peeking?

Take the timed Quiz: Magic Methods and Properties quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →