With the expression 'abc%rdef' % obj part '%r' is replaced with repr(obj)
With the expression 'ABC%sDEF' % obj part '%s' is replaced with str(obj)
.
repr () is a function that, for ordinary objects, returns a string that matches the one you must write to the script to determine the object passed as repr () argument:
For many types, this function tries to return a string that will give an object with the same value when passed to eval () http://docs.python.org/library/functions.html#repr
.
Example 1
if you consider the list defined by li = [12,45,'haze']
print li will print [12,45, 'haze']
print repr(li) also print [12,45, 'haze'] because [12,45,'haze'] is a sequence of characters written in a script to define a list li with this value
Example 2
if you consider the string defined by ss = 'oregon' :
print ss will print oregon without quotes around
print repr(ss) will print 'oregon', since 'oregon' is a sequence of characters that you must write to the script if you want to define an ss string with the value oregon in the program
.
Thus, this means that in fact for common objects, repr () and str () return strings that are generally equal, with the exception of a string object. This makes repr () especially interesting for string objects. It is very useful to parse the contents of HTML codes, for example.