繁体   English   中英

如何将普通字符串转换为 Python 中的转义字符?

[英]How to convert a normal string to escape characters in Python?

我想用所有转义字符转换字符串。

输入

string = "Let's do this"
convert(string)

Output

Let\'s do this

谢谢你!

你的问题不清楚。 转义字符是指在某些字符之后添加新行还是只想在字符串中添加反斜杠?

如果您想在 ' 字符之前添加反斜杠,您可以在下面尝试。

new_string = string.replace("'s", "\\'s")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM