I need to replace some characters as follows: & ➔ \\&, # ➔ \\#, ...
&
\\&
#
\\#
I coded as follows, but I guess there
>>> string="abc&def#ghi" >>> for ch in ['&','#']: ... if ch in string: ... string=string.replace(ch,"\\"+ch) ... >>> print string abc\&def\#ghi