How do I replace slash character "'' by backslash character "/" in python
Question:
I need to replace forward slash ""
with backward slash "/"
.
I have tried:
c = "/r/tes/integrtest_Ame.txt"
x = c.replace("", "/")
print(x)
But I have got the error:
File "C:Usersbwar1korDesktopTesttest.py", line 33
x = c.replace("", "/")
^
SyntaxError: EOL while scanning string literal
Answers:
” is an escape character, to use the actual character itself you need to double it:
c = r"/r/tes/integrtest_Ame.txt"
x = c.replace("\", "/")
print(x)
I need to replace forward slash ""
with backward slash "/"
.
I have tried:
c = "/r/tes/integrtest_Ame.txt"
x = c.replace("", "/")
print(x)
But I have got the error:
File "C:Usersbwar1korDesktopTesttest.py", line 33
x = c.replace("", "/")
^
SyntaxError: EOL while scanning string literal
” is an escape character, to use the actual character itself you need to double it:
c = r"/r/tes/integrtest_Ame.txt"
x = c.replace("\", "/")
print(x)