如何在Python中读取多行原始输入?
我想创建一个Python程序,该程序需要多行用户输入。例如:
This is a multilined input.It has multiple sentences.
Each sentence is on a newline.
如何接收多行原始输入?
回答:
sentinel = '' # ends when this string is seenfor line in iter(raw_input, sentinel):
pass # do things here
要将每一行作为字符串获取,你可以执行以下操作:
'\n'.join(iter(raw_input, sentinel))
Python 3:
'\n'.join(iter(input, sentinel))
以上是 如何在Python中读取多行原始输入? 的全部内容, 来源链接: utcz.com/qa/428972.html