Python “string_escape” vs “unicode_escape”
问题 According to the docs, the builtin string encoding string_escape : Produce[s] a string that is suitable as string literal in Python source code ...while the unicode_escape : Produce[s] a string that is suitable as Unicode literal in Python source code So, they should have roughly the same behaviour. BUT, they appear to treat single quotes differently: >>> print """before '" \0 after""".encode('string-escape') before \'" \x00 after >>> print """before '" \0 after""".encode('unicode-escape')