The result '\\&' is only displayed – actually the string is \&:
>>> str="&"
>>> new_str = str.replace('&', '\&')
>>> new_str
'\\&'
>>> print new_str
\&
Try it in a shell.
The result '\\&' is only displayed – actually the string is \&:
>>> str="&"
>>> new_str = str.replace('&', '\&')
>>> new_str
'\\&'
>>> print new_str
\&
Try it in a shell.