摆脱句子中的输入空格

时间:2017-03-22 09:20:22

标签: python

我有一个看起来像这样的字符串:

<type 'str'>
Hi George,

Thanks for sending me your report.

Ill take a look at it and get back to you tomorrow.

我想做的是将其转换为一个字符串,如下所示:

Hi George, Thanks for sending me your report. Ill take a look at it and get back to you tomorrow.

有关如何做到这一点的想法吗?

2 个答案:

答案 0 :(得分:5)

使用此:

>>> print(" ".join(input_str.split()))
'Hi George, Thanks for sending me your report. Ill take a look at it and get back to you tomorrow.'

答案 1 :(得分:0)

strin  = # Your string
a = strin.replace ('\n',' ')
print (a)

结果:
Hi George, Thanks for sending me your report. Ill take a look at it and get back to you tomorrow.

由于您希望句子之间有空格,而不是空行,因此请用空格替换换行符。