how to replace back slash character with empty string in python [duplicate]

We need to specify that we want to replace a string that contains a single backslash. We cannot write that as "\", because the backslash is escaping the intended closing double-quote. We also cannot use a raw string literal for this: r"\" does not work.

Instead, we simply escape the backslash using another backslash:

result = string.replace("\\","")

Leave a Comment