0

Here is a simple code I was playing with

input("This is test:")
input("This is test:")
input("This is test:")

So, it prompted me to give some input and when I entered input as numbers, I got the following output.

This is test:1

This is test:2

This is test:3

So, I am wondering where the extra lines coming from. The documentation says that input function strips newline character at the end. So, where do extra lines come from ?

Thanks

user9026
  • 852
  • 2
  • 9
  • 20
  • 5
    I am not getting this behaviour. – Albin Paul Jan 31 '22 at 08:55
  • How are you running this code? – Nineteendo Jan 31 '22 at 08:55
  • Does this answer your question? [Extra line in output when printing inside a loop](https://stackoverflow.com/questions/10456293/extra-line-in-output-when-printing-inside-a-loop) – Fran Arenas Jan 31 '22 at 08:56
  • I have put the code in file inside Spyder(Python 3.8) Anaconda and checking the output. – user9026 Jan 31 '22 at 09:02
  • are you using this: `print(input("This is test:"))` Then you must know that print appends a newline, and the input lines already end with a newline. – Fareed Khan Jan 31 '22 at 09:04
  • @Fareed, no. I am not using any print function here. I just put the code I showed in .py file and run it inside Anaconda Spyder. I tried closing and restarting again. Same output again with extra line. – user9026 Jan 31 '22 at 09:05
  • isn't this caused by your command line? I am not getting this behavior – Rizquuula Jan 31 '22 at 09:10
  • Not on command line. Inside Spyder console. On command line, I get the expected output – user9026 Jan 31 '22 at 09:11
  • 2
    @user9026, this may help: https://stackoverflow.com/questions/44667227/how-can-i-prevent-spyder-from-inserting-a-new-line-after-taking-user-input – Fareed Khan Jan 31 '22 at 09:16

0 Answers0