Python只识别多行中的第一行

标签 python

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

圣经=输入() 如果我粘贴

不为任何事忧虑,但凡事忧虑,
通过祈祷和请愿,带着感恩,
向神提出你的要求。

删除空格后,例如 bible = bible.replace(' ',''), 当最后 print(bible) 时,它只是打印出来

不要对任何事情感到焦虑,而是对所有事情(只是第一行)。
第二、第三行消失了。

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 3

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

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

关于Python只识别多行中的第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58262778/

相关文章:

python - 迭代 python 字典的键,当键是整数时,我得到这个错误, "TypeError: argument of type ' int' 不可迭代”

python 子进程抛出错误 "no such file or direcrory"

python - pycuda "nvcc fatal : Cannot find compiler ' cl.exe' 在路径中”

python - 在 SQLAlchemy 中使用 1-N 关系

python - Selenium Python 按名称查找元素不起作用

python - 在 python 中复制文本文件的最后三行?

python - 处理可选函数参数

Python Web Scraping 关闭但未完成且未给出错误

python - 如何创建批量剪切音频的方法?

python - COM 和 Windows DLL 之间有什么关系?