Although Str (), repr () and ' operations are very similar in terms of features and functions, the fact that repr () and ' ' are doing exactly the same thing, they return an "official" string representation of an object, which means that in most cases it can be evaluated (using the built-in function eval () ) to get the object back.
But Str () is different, and STR () is committed to generating an object's readable string representation, and its return results are usually not available for eval () evaluation, but are well suited for print statement output. Again, not all strings returned by REPR () are able to use the eval () built-in function to get the original object. This means that the repr () output is friendly to Python, and the output of STR () is more user friendly.
Even so, in many cases the output of the three is still exactly the same. You can look at the following code to compare
>>> s = ' Hello, world '
>>> Str (s)
' Hello, world. '
>>> Repr (s)
"' Hello, world. '"
>>> Str (0.1)
' 0.1 '
>>> Repr (0.1)
' 0.10000000000000001 '
>>> x = 10 * 3.25
>>> y = 200 * 200
>>> s = ' The value of x is ' + repr (x) + ', and y is ' + repr (y) + ' ... '
>>> Print S
The value of x is 32.5, and Y is 40000 ...
>>> # The REPR () of a string adds string quotes and backslashes:
... hello = ' Hello, world\n '
>>> hellos = repr (hello)
>>> Print Hellos
' Hello, world\n '
>>> # The argument to Repr () May is any Python object:
... repr ((x, y, (' spam ', ' eggs ')))
"(32.5, 40000, (' spam ', ' eggs ')")
The difference between Python str repr