6 Answers
6

In Python, there are two builtin functions for turning an object into a string: str vs. repr. str is supposed to be a friendly, human readable string. repr is supposed to include detailed information about an object's contents (sometimes, they'll return the same thing, such as for integers). By convention, if there's a Python expression that will eval to another object that's ==, repr will return such an expression e.g.

Adding to the replies given above, '%r' can be useful in a scenario where you have a list with heterogeneous data type.
Let's say, we have a list = [1, 'apple' , 2 , 'r','banana']
Obviously in this case using '%d' or '%s' would cause an error. Instead, we can use '%r' to print all these values.