I have to replace in a string the character '/' with '\' I use
str.replace('/','\')
but got this error:
Lexical error at line..., column .... Encountered: "\r" (13), after : ""
Join Stack Overflow to learn, share knowledge, and build your career.
I have to replace in a string the character '/' with '\' I use
str.replace('/','\')
but got this error:
Lexical error at line..., column .... Encountered: "\r" (13), after : ""
'\'
is used for escape sequences so if you want to use it you have to escape that character:
str.replace('/','\\')
See the python documentation on string literals for more information.
The backslash has a special meaning in strings. Use '\\'
instead.
you need to use Escape Sequence
>>> m="hell/o"
>>> k=m.replace('/','\\')
>>> print k
hell\o