-1

I searched the first page of Google but couldn't find an answer. This won't happen for int(raw_input()) weirdly enough. But if i type:

a = [raw_input() for i in range(int(raw_input()))]
print(a)

Example input: 5 1 2 3 4 5

The output will be: ['1\n', '2\n', '3\n', '4\n', '5\n']

I know this has something to do with the IDE (I run VSCode) but I have no clue how to fix it. Thank you.

12
  • just use int(input()) instead of int(raw_input()). Raw input will return you all the details including the \n Commented Jan 27, 2021 at 0:50
  • geeksforgeeks.org/…. Also see more information here stackoverflow.com/questions/5563089/… Commented Jan 27, 2021 at 0:51
  • @JoeFerndz Thanks, but that's not my question, int(raw_input()) works fine. But raw_input() at some random point today began adding \n to each input when it never did that before. I need to use raw_input because it shaves off a decent amount of time off my CP submissions. I'm not interested in the niche uses of raw_input, I'm looking at how to fix this bug. Commented Jan 27, 2021 at 0:56
  • raw_input() will always return a string value. You need to convert it to an integer if you want integer. Commented Jan 27, 2021 at 0:58
  • btw, if you are using 3.9 or above, PEP 3111: raw_input() was renamed to input(). That is, the new input() function reads a line from sys.stdin and returns it with the trailing newline stripped. It raises EOFError if the input is terminated prematurely. To get the old behavior of input(), use eval(input()). Commented Jan 27, 2021 at 0:59

1 Answer 1

0

In Python3.x, raw_input() and input() are integrated, raw_input() is removed, only the input() function is retained, which receives any input, defaults all input to string processing, and returns the string type.

When use Python2.7:

enter image description here

When use Python3.8:

enter image description here

In addition, if you use extensions for debugging other than the python extension in VS Code, please try to disable it to avoid affecting the results.

My environment:

VS Code: 1.52.1 (user setup); OS: Windows_NT x64; VS Code extension: Python; Pylance;

Reference: What's new in Python3.

Sign up to request clarification or add additional context in comments.

1 Comment

You're goated. It was because of a new python update. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.