The str() function is meant to return representations of values which are fairly
human-readable, while repr() is meant to generate representations which can be read by
the interpreter (or will force a SyntaxError if there is not equivalent syntax). For
objects which don't have a particular representation for human consumption, str() will
return the same value as repr(). Many values, such as numbers or structures like lists
and dictionaries, have the same representation using either function. Strings and
floating point numbers, in particular, have two distinct representations.
>>> try:<br />raise Exception(1,2,3);<br />except Exception as e:<br />print(e);<br />print(repr(e));<br />print(str(e));<br />print(e.args);</p><p>(1, 2, 3)<br />Exception(1, 2, 3)<br />(1, 2, 3)<br />(1, 2, 3)<br />>>> s = 'hello world'<br />>>> str(s)<br />'hello world'<br />>>> repr(s)<br />"'hello world'"