pythonnewline

New line for input in Python


I wanted to make a simple program that would take an input and then print it back out. This is how my code looks:

Number = raw_input("Enter a number")
print Number

How can I make it so a new line follows the prompt? I read about using \n, but when I tried:

Number = raw_input("Enter a number")\n
print Number

it didn't work.


Solution

  • Put it inside of the quotes:

    Number = raw_input("Enter a number\n")
    

    \n is a control character, sort of like a key on the keyboard that you cannot press.


    You could also use triple quotes and make a multi-line string:

    Number = raw_input("""Enter a number
    """)