小编Cha*_*edy的帖子

在python中替换反斜杠'\'

尝试在python中替换'\'时,数据更改并给我未知的字母。

我已经尝试过string.replace,re.sub,regex_replace

a = '70\123456'
b = '70\123\456'

a = a.replace('\\','-')
b = b.replace('\\','-')
Run Code Online (Sandbox Code Playgroud)

预期结果:

a = '70-123456'
b = '70-123-456'
Run Code Online (Sandbox Code Playgroud)

但是实际结果是:

a = 70S456
b = 70S?
Run Code Online (Sandbox Code Playgroud)

有什么问题以及如何解决?

python replace python-unicode

-1
推荐指数
1
解决办法
68
查看次数

标签 统计

python ×1

python-unicode ×1

replace ×1