Escape for str in Python

前端 未结 6 1529
星月不相逢
星月不相逢 2021-01-25 02:45

Wow, this should be so simple, but it\' just not working. I need to inset a \"\\\" into a string (for a Bash command), but escaping just doesn\'t work.

>>&         


        
6条回答
  •  忘掉有多难
    2021-01-25 03:17

    Python's quoting the backslash again when it shows you the representation of the string (in such a way that you could paste it in and get the string with an escaped backslash).

    If you print the string, you'll see there's only one in the actual string.

    >>> print "hello\\world"
    hello\world
    

提交回复
热议问题