Oli*_*own 2 python newline strip python-3.x
我正在尝试\n使用strip()命令从句子中删除字符,但它似乎不起作用。
str1 = "Hello World \n, I\n am \nhere"
print(str1.strip())
Run Code Online (Sandbox Code Playgroud)
输出
Hello World
, I
am
here
Run Code Online (Sandbox Code Playgroud)
strip()仅从开头和结尾删除空白字符(换行符、制表符、空格)。在\n使用之间删除replace()
>>> str1 = "Hello World \n, I\n am \nhere"
>>> print(str1.replace('\n', ''))
Hello World , I am here
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4236 次 |
| 最近记录: |