更新时间:2023-02-09 13:31:00
你可以简单地使用 replace()
来做到这一点,就像 data.replace('\n\n', '\n')
You can simply do this by using replace()
like data.replace('\n\n', '\n')
参考这个例子以更好地理解.!!
Refer this example for better understanding.!!
data = '1\n\n2\n\n3\n\n'
print(data)
data = data.replace('\n\n', '\n')
print(data)
输出
1
2
3
1
2
3