【发布时间】:2022-01-15 02:38:28
【问题描述】:
我想知道如何使用 Python 的 str.replace() 函数(或类似函数)来替换反斜杠...
当我尝试这样做时:
>>> temp = r"abc\abc"
>>> temp.replace(r'\'', 'backslash')
'abc\\abc' # For some reason, temp.replace() does not replace '\' with 'backslash' even when using raw variable
>>> temp.replace(r'\\', 'backslash') # Same result
'abc\\abc'
我该如何解决这个问题?为什么? (Linux、Debian/Ubuntu、x86_x64 处理器)
【问题讨论】:
标签: python string replace backslash