Adding backslashes without escaping [duplicate]

The result '\\&' is only displayed – actually the string is \&:

>>> str="&"
>>> new_str = str.replace('&', '\&')
>>> new_str
'\\&'
>>> print new_str
\&

Try it in a shell.

Leave a Comment