python - 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 3 为我工作
if __name__ == "__main__":
bible = ''.join(iter(input, ''))
bible = bible.replace(' ','')
print(bible)
结果:不要对任何事情感到焦虑,但通过祈祷和祈求,感恩,向上帝提出你的要求。
推荐阅读
- git - 列出作为 git 合并冲突解决的一部分的文件,无论更改如何
- perl - 如何对 Data::Printer 的输出进行排序?
- javascript - Sequelize 从响应中删除枢轴数据
- node.js - 如何修复云错误“必须提供 api_key”
- python - 具有不同组的散点图和每组的边缘直方图
- cypher - 如何在 gremlin 查询中使用多个联合步骤?
- php - 在 PHP 中组合数据以插入 SQL 的最佳方法是什么?
- dm-script - DM 脚本计算具有给定 ROI 的曲线下面积
- c++ - 有没有办法在 VS 2019 中将 C++ 可执行文件与 DLL 合并?
- go - 有没有办法验证 git sha 是否属于带有 go-github 客户端的 git 分支?