1.11M Members

how do i go onto a new line in python

 
0
 

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

 
0
 

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.

 
1
 

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

 
1
 

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 = '')
 
0
 

Oh right.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article