我想创建一个接受多行用户输入的 Python 程序。例如:
This is a multilined input.
It has multiple sentences.
Each sentence is on a newline.
如何接收多行原始输入?
最佳答案
sentinel = '' # ends when this string is seen
for line in iter(input, sentinel):
pass # do things here
将每一行作为字符串,您可以做:
'\n'.join(iter(input, sentinel))
Python 2:
'\n'.join(iter(raw_input, sentinel))
关于python - 如何读取多条原始输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11664443/