python3怎样进行多行输入

import syslist = list_new = #定义一个空列表for line in sys.stdin: #py.3中input()只能输入一行 sys.stdin按下换行键然后ctrl+d程序结束 list_new = line.split() list.extend(list_new)#每一行组成的列表合并print(list)如输入
Bbox Money Pythonlines number #输入为两行后按下换行键,光标调到下一行 ,按下ctrl+d程序结束输出为
Bbox Money Python lines number可实现多行数据合并及下一步

点个赞吧

■网友
Raw input across multiple lines in Pythonsentinel = \u0026#39;end\u0026#39; # 遇到这个就结束lines = for line in iter(input, sentinel): lines.append(line)#如果想要提示,可以这样:from functools import partialinputNew = partial(input,\u0026#39;Input something pls:\\u0026#39;)sentinel = \u0026#39;end\u0026#39; # 遇到这个就结束lines = for line in iter(inputNew, sentinel): lines.append(line)\u0026#39;\u0026#39;\u0026#39;Input something pls:萌Input something pls:萌Input something pls:哒Input something pls:!Input something pls:endIn : \u0026#39;\u0026#39;.join(lines)Out: \u0026#39;萌萌哒!\u0026#39;\u0026#39;\u0026#39;\u0026#39;
■网友
输入一行之前按TAB或者两个空格。
■网友
lines = words = input("请输入内容(单独输入\u0026#39;:w\u0026#39;保存退出):")while words != \u0026#39;:w\u0026#39;: line = lines.append(words) words = input()print(lines)\u0026#39;:w\u0026#39;字符串是停止的字符串,而且不会加入到lines列表中.
可以用writelines()方法把lines里的数据写到文件里,Down!

■网友
list = while list != \u0026#39;end\u0026#39;: list.append(input(\u0026#39;请输入:\u0026#39;))for line in list: print(line)python3怎样进行多行输入

【python3怎样进行多行输入】


    推荐阅读