Start New Discussion within our Software Development Community

for example if i write hello on one line and then wanted to write goodbye right underneath what do i have to do? as when i press the enter key it just prints hello

The newline character in python is '\n'.

print "Hello\nGoodbye"

or for python 3:

print("Hello\nGoodbye")

The print statement in python (except python 3) automatically adds a newline at the end.

The print statement in python (except python 3) automatically adds a newline at the end.

Should be noted that this can be prevent by doing the following

print "Hello World",

Yup a trailing ','
:)

Chris

The print statement in python (except python 3) automatically adds a newline at the end.

Wait, i think that in python 3 there is an automatic \n at the end of lines. Here are the default args for print()

print - sep = ' ', end = '\n', file = sys.stdout

So that seems to point towards print actually adding a new line to the end.

Also if you do not want this then just go

print ("Hello there", end = '')
This article has been dead for over six months. Start a new discussion instead.