【问题标题】:Input a multiline string in python [duplicate]在python中输入多行字符串[重复]
【发布时间】:2015-04-29 07:04:15
【问题描述】:

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

输入:

a
b
c

我知道我可以在 python 2.7.5 中使用以下方法轻松做到这一点:

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

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

然而在 python 3 中,这一行:

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

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

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

【问题讨论】:

  • 我相信这是相关的。 stackoverflow.com/questions/11664443/…
  • 在最多读一行的raw_input() 的输出上调用.splitlines() 是没有意义的。
  • 这根本不是重复的问题。正如问题所说,这与python 2而不是python 3有关。

标签: python python-3.x input


【解决方案1】:

试试吧。

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

【讨论】:

  • @DSM 哦对了,我忘了,我改成input,谢谢。
猜你喜欢
  • 2018-11-02
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-17
相关资源
最近更新 更多