[英]How to add a backlash (\) at the beginning and the end of a string in Python
我正在嘗試在Python字符串的開頭和結尾添加反沖符號(\\)。 使用下面列出的代碼時,等號右側的所有內容在我的開發環境(Eclipse)上變為綠色,並且出現錯誤消息。
mystring = "\" + mystring + "\"
原版的:
>>> print "\hello\"
File "<stdin>", line 1
print "\hello\"
^
SyntaxError: EOL while scanning string literal
雙:
>>> print "\\hello\\"
\hello\
>>>
參見頁面https://docs.python.org/2.0/ref/strings.html
escapeseq:“ \\” +任何ASCII字符
mystring = "\\mystring\\"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.