print([obj]) where obj defines both __str__ and __repr__. Which one is used for obj?
Options
__str____repr__(Correct option)__format__- Neither: it prints the memory address
Answer
__repr__
Why
__str__ returns friendly text for users. __repr__ returns precise text for developers.
When Python prints a list, it shows each element with repr(), because it wants unambiguous output.
So print([obj]) uses __repr__, while print(obj) uses __str__.
Remember
Containers show their items with repr().