2017-02-16 74 views

回答

3

您需要將原始字符串,以獲得解釋結果解碼:

>>> i = r'\nwow' 
>>> print(i) 
\nwow 
>>> print(i.decode('string_escape')) 

wow 
>>> 

請注意,你不會得到公正wow,因爲字符串是\nwow因此間隙,當我打印出來;還要小心逃脫,因爲字符串現在已更改:

>>> q = i.decode('string_escape') 
>>> len(q) == len(i) 
False 
>>> q 
'\nwow' 
>>> i 
'\\nwow'