如何在Python中读取多行原始输入? [英] How do I read multiple lines of raw input in Python?
本文介绍了如何在Python中读取多行原始输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个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:
'\n'.join(iter(raw_input, sentinel))
Python 3:
Python 3:
'\n'.join(iter(input, sentinel))
这篇关于如何在Python中读取多行原始输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文