943,703 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 36828
  • Python RSS
Feb 8th, 2009
0

how do i go onto a new line in python

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darkfury18 is offline Offline
3 posts
since Feb 2009
Feb 8th, 2009
0

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

The newline character in python is '\n'.
python Syntax (Toggle Plain Text)
  1. print "Hello\nGoodbye"
or for python 3:
python Syntax (Toggle Plain Text)
  1. print("Hello\nGoodbye")

The print statement in python (except python 3) automatically adds a newline at the end.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Feb 8th, 2009
1

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

Click to Expand / Collapse  Quote originally posted by scru ...
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
Python Syntax (Toggle Plain Text)
  1. print "Hello World",
Yup a trailing ','


Chris
Last edited by Freaky_Chris; Feb 8th, 2009 at 5:20 pm.
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Feb 8th, 2009
1

Python 3 seems to add a new line

Click to Expand / Collapse  Quote originally posted by scru ...
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
python Syntax (Toggle Plain Text)
  1. print ("Hello there", end = '')
Last edited by Paul Thompson; Feb 8th, 2009 at 6:16 pm.
Reputation Points: 264
Solved Threads: 183
Veteran Poster
Paul Thompson is offline Offline
1,095 posts
since May 2008
Feb 8th, 2009
0

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

Oh right.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Parameters and Return Values
Next Thread in Python Forum Timeline: A+ Study tool in python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC