How to remove backslash from string in Python?
Question:
I need to remove backslash (''
) from string in Python.
str2 = str1.replace('', '')
isn`t working.
How can i do it?
Answers:
This is due to being the escape sequence character in python so you have to do \
str2 = str1.replace('\', '')
There are 2 ways you can do that:
You have to escape the
:
str2 = str1.replace('\', '')
or using raw strings:
str2 = str1.replace(r'', '')
Little tricky but it works
str2 = str1.replace(" ".replace(" ", ""), "")
I need to remove backslash (''
) from string in Python.
str2 = str1.replace('', '')
isn`t working.
How can i do it?
This is due to being the escape sequence character in python so you have to do \
str2 = str1.replace('\', '')
There are 2 ways you can do that:
You have to escape the :
str2 = str1.replace('\', '')
or using raw strings:
str2 = str1.replace(r'', '')
Little tricky but it works
str2 = str1.replace(" ".replace(" ", ""), "")