簡體   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