When I run this code
formatter = "%s %s %r %r" print formatter % (1, 2, 3 , 4) print formatter % ('one', 'two', 'three', 'four') print formatter % (True, False, False, True) print formatter % (formatter, formatter, formatter, formatter) print formatter % ( "I had this thing.", "That you could type up right.", "But it didn't sing.", "So I said goodnight." ) The output of this line
print formatter % (formatter, formatter, formatter, formatter) is
%s %s %r %r %s %s %r %r '%s %s %r %r' '%s %s %r %r' Now I understand that in python we use %r for debugging reasons and specified formatters like %s for the user thats why the (' ') is added when %r is used. What I don't understand is why is the only the first 2 without single quotes and not all of them?! How was that line executed briefly?
__repr__adds extra quotes to string.__str__doesn't.