我想创建一个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(raw_input, sentinel): pass # do things here
要将每一行作为字符串获取,你可以执行以下操作:
'\n'.join(iter(raw_input, sentinel))
Python 3:
'\n'.join(iter(input, sentinel))