在python中输入多行字符串 [英] Input a multiline string in python

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

问题描述

我正在尝试创建一个简单的程序,该程序输入一个多行输入并将其作为表格输出.

I am trying to create a simple programme that inputs a single multiline input and outputs it as a table.

输入:

a
b
c

我知道我可以通过使用以下命令在python 2.7.5中轻松完成此操作:

I know i could have done this is easily in python 2.7.5 by using:

input_string = raw_input("> ").splitlines()

这将返回['a','b','c']

this would return ['a', 'b', 'c']

但是在python 3中,该行:

however in python 3, the line:

input_string = input("> ").splitlines()

仅返回 ['a'] ,因此它仅读取输入字符串的第一行.

only returns ['a'] hence it only reads the first line of the input string.

python 3中有什么方法可以接受多行输入吗?谢谢.

Is there any way in python 3 to accept a multiline input? Thanks.

推荐答案

尝试一下.

aux = ''
'\n'.join(iter(input, aux))

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

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