首页 > 解决方案 > Python 只识别多行中的第一行

问题描述

如果我一次粘贴多行输入,我的程序只识别第一行。

bible = input() 如果我粘贴

不要为任何事情忧虑,但凡事,
借着祷告和祈求,带着感恩,
将你的要求呈献给神。

并在删除空白后,例如 bible = bible.replace(' ',''),当最终打印(圣经)时,它只是打印出来

不要对任何事情感到焦虑,但对所有事情(只是其中的第一行)。
2、3行没了。

bible = ()
bible = bible.replace(' ','')
print(bible)

我的意见是

Do not be anxious about anything, but in everything,  
by prayer and petition, with thanksgiving,  
present your requests to God.

预期输出是

Donotbeanxiousaboutanything,butineverything,byprayerandpetition,withthanksgiving,presentyourrequeststoGod.

我不仅想包括第一行输入,还包括其余的输入,也包括在一个字符串中。

标签: python

解决方案


它可以使用 python 3 为我工作

if __name__ == "__main__":
bible = ''.join(iter(input, ''))
bible = bible.replace(' ','')
print(bible)

结果:不要对任何事情感到焦虑,但通过祈祷和祈求,感恩,向上帝提出你的要求。


推荐阅读