how do i go onto a new line in python

Reply

Join Date: Feb 2009
Posts: 3
Reputation: darkfury18 is an unknown quantity at this point 
Solved Threads: 0
darkfury18 darkfury18 is offline Offline
Newbie Poster

how do i go onto a new line in python

 
0
  #1
Feb 8th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,606
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: how do i go onto a new line in python

 
0
  #2
Feb 8th, 2009
The newline character in python is '\n'.
  1. print "Hello\nGoodbye"
or for python 3:
  1. print("Hello\nGoodbye")

The print statement in python (except python 3) automatically adds a newline at the end.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: how do i go onto a new line in python

 
1
  #3
Feb 8th, 2009
Originally Posted by scru View Post
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
  1. print "Hello World",
Yup a trailing ','


Chris
Last edited by Freaky_Chris; Feb 8th, 2009 at 5:20 pm.
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 902
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 145
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Python 3 seems to add a new line

 
1
  #4
Feb 8th, 2009
Originally Posted by scru View Post
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
  1. print ("Hello there", end = '')
Last edited by Paul Thompson; Feb 8th, 2009 at 6:16 pm.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,606
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 130
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: how do i go onto a new line in python

 
0
  #5
Feb 8th, 2009
Oh right.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC