如何在Python的输入中读取多行? [英] How to read more than one line in an input in Python?

查看:1570
本文介绍了如何在Python的输入中读取多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Python中输入多行内容.但是当我尝试然后打印结果时,它打印的只是第一行.是否可以从输入中也读取第一行以下的行?

I want to input more than one line in Python. But when I try to and then I print the result, all it prints is the first line. Is there a way to read also the lines from the input that are below the first line?

例如:

lista=input('Insert the data here: ')
print(' ')
print(lista)

假设我要输入:

你好1乔

由2个汤姆

真的4了

但是它只打印第一行.

But it only prints the first line.

关于如何读取输入中的其他行以便以后可以打印它们的任何想法吗?

Any idea about how to read the other lines in the input so that I can print them afterwards?

推荐答案

如果您想阅读3行输入.你可以这样

If you wanna read 3 line of input. You can do like this.

inputs = [input() for i in range(3)]

inputs变量将是一个列表

这篇关于如何在Python的输入中读取多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆