Python raw_input ignore newline

前端 未结 2 1246
生来不讨喜
生来不讨喜 2021-01-05 03:10

Is there a way to ignore newline characters in data entered through raw_input? I am trying to use raw_input to input a list of strings that are copied and pasted from a spr

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 04:00

    I am not sure what you are trying to ask but when you use raw_input(), it strips a trailing newline.

    And the doc says the same too.

    If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.

提交回复
热议问题