如何读取多行原始输入? [英] How to read multiple lines of raw input?
本文介绍了如何读取多行原始输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个接受多行用户输入的 Python 程序.例如:
I want to create a Python program which takes in multiple lines of user input. For example:
This is a multilined input.
It has multiple sentences.
Each sentence is on a newline.
如何接收多行原始输入?
How can I take in multiple lines of raw input?
推荐答案
sentinel = '' # ends when this string is seen
for line in iter(raw_input, sentinel):
pass # do things here
要将每一行都作为一个字符串,你可以这样做:
To get every line as a string you can do:
'
'.join(iter(raw_input, sentinel))
<小时>
Python 3:
Python 3:
'
'.join(iter(input, sentinel))
这篇关于如何读取多行原始输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文