简体   繁体   English

在python中接受换行符

[英]Accept newline character in python

I want to accept new line input in python.我想在 python 中接受新行输入。

I am trying我在尝试

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

But when i input paragraph.. on the very first ENTER it stops taking further input lines.但是当我输入段落.. 在第一个 ENTER 时,它停止采取进一步的输入行。

So how to accept newline character as input in Python那么如何在 Python 中接受换行符作为输入

and then how to print the paragraph as it is on the screen.?然后如何在屏幕上打印段落。?

EDIT: This answer assumes that you are using Python 3. If you are using Python 2.x, use the one provided by Anthon.编辑:此答案假定您使用的是 Python 3。如果您使用的是 Python 2.x,请使用 Anthon 提供的那个。

Do something like this:做这样的事情:

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

For example, you want to end the input sequence by an extra newline character, then the code would be:例如,您想以额外的换行符结束输入序列,则代码为:

text = ''
while True:
    dummy = input('''Enter the paragraph :''')+'\n'
    if dummy=='\n':
        break
    text += dummy

from Python 3: receive user input including newline characters来自Python 3:接收用户输入,包括换行符

i have done the below :我做了以下工作:

import sys


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

and this make my task.这使我的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM