1

我想在 python 中接受新行输入。

我在尝试

s = input('''Enter the paragraph :''')

但是,当我在第一个 ENTER 上输入段落时,它会停止进一步输入行。

那么如何在Python中接受换行符作为输入

然后如何在屏幕上打印段落。?

4

2 回答 2

1

编辑:此答案假定您使用的是 Python 3。如果您使用的是 Python 2.x,请使用 Anthon 提供的那个。

做这样的事情:

text = ''
while True: # change this condition.
    text += input('''Enter the paragraph :''')+'\n' #UPDATED. Appended a \n character.

例如,您想通过一个额外的换行符结束输入序列,那么代码将是:

text = ''
while True:
    dummy = input('''Enter the paragraph :''')+'\n'
    if dummy=='\n':
        break
    text += dummy
于 2013-06-12T05:55:36.340 回答
1

来自Python 3:接收用户输入,包括换行符

我做了以下事情:

import sys


text = sys.stdin.read()
print(text)

这就是我的任务。

于 2013-06-12T06:11:19.787 回答