← 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?
- A.The default <object at 0x...> text
- B.repr, because str falls back to it
- C.Nothing; it raises an error
- 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 →