Input a multiline string in python [duplicate]

2019-08-08 10:21发布

This question already has an answer here:

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

input:

a
b
c

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

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

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

however in python 3, the line:

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

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

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

1条回答
混吃等死
2楼-- · 2019-08-08 10:57

just try.

aux = ''
'\n'.join(iter(input, aux))
查看更多
登录 后发表回答