print OBJECT calls OBJECT.__str__(), then when OBJECT.__repr__() is called? I see that print OBJECT calls OBJECT.__repr__() when OBJECT.__str__() doesn’t exist, but I expect that’s not the only way to call __repr__().
print OBJECT calls OBJECT.__str__() , then when OBJECT.__repr__() is called? I see that print
Share
calls
the purpose of
__repr__is that it provides a ‘formal’ representation of the object that is supposed to be a expression that can beevaled to create the object. that is,should, but does not always in practice, yield
TrueI was asked in the comments for an example of when
obj != eval(repr(obj)).here’s another one: