%s specifier convert object dùng str(), %r convert dùng repr().
Với object như integer, cho cùng kết quả, nhưng repr() đặc biệt: (với type hỗ trợ) conventionally trả về kết quả là valid Python syntax, có thể dùng recreate object unambiguously. Ví dụ, string có endline char, %s show xuống dòng thực, %r show \n và giữ quote.
Ví dụ
>>> string = "Hello\nworld" >>> print "Example: %s" % string Example: Hello world >>> print "Example: %r" % string Example: 'Hello\nworld'
Biểu thức thứ 2 dùng recreate object được.