2015-07-12 38 views

回答

1

是的。反斜槓轉義序列仍然存在在Python 3的字符串,r前綴從而原始字符串使如圖這個簡單的例子的差:

>>> s = 'hello\n' 
>>> raw = r'hello\n' 
>>> s 
hello\n 
>>> raw 
hello\\n 
>>> print(s) 
hello 

>>> print(raw) 
hello\n 
1

原始字符串仍然是寫像\字符而不脫離它們是有用的。這在正則表達式和窗口路徑等方面通常很有用。

相關問題