Search code examples
pythonbackslash

How to remove backslash from string in Python?


I need to remove backslash ('\') from string in Python.

str2 = str1.replace('\', '') isn`t working.

How can i do it?


Solution

  • This is due to \ being the escape sequence character in python so you have to do \\

    str2 = str1.replace('\\', '')