For example,
python
>> x = 1
>> x
1
I'm curious about what method/function on x
is returning 1. I'm asking because I'm seeing differences between calling print x
and simply x
.
Similary, is there a way to specify what is called? Does this configuration exist in IPython?
When you inspect an object in that manner in a REPL, it invokes the object's
__repr__
method. In comparison,print
uses the object's__str__
method. Example:When defining
__repr__
and__str__
for your own classes, try to follow the documentation's suggestions regarding which one should be more detailed and "official".