>>> b = 'first \\n second \n third \\n forth \n fifth \\n'
>>> print(b)
first \n second
third \n forth
fifth \n
b 到想要的結果,
print( result )
first \n second third \n forth fifth \n
result = 'first \n second third \n Fourth Fifth \n'
怎么做?
uj5u.com熱心網友回復:
\n是轉義字符,表示換行符,while\\n是反斜杠和字母 n,洗掉時不受影響\n:
>>> b = 'first \\n second \n third \\n forth \n fifth \\n'
>>> b.replace('\n', '')
'first \\n second third \\n forth fifth \\n'
這個例子可能會讓你意識到它們之間的區別:
>>> len('\n')
1
>>> list('\n')
['\n']
>>> len('\\n')
2
>>> list('\\n')
['\\', 'n']
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/467300.html
上一篇:將列合并為二維串列中的一個字串
