-10

I am doing python reasonably well but I'm not sure on how to print a space in my code.

Usually I just type:

print("")

Is there a more efficient way I can do this?

Nissa
  • 4,636
  • 8
  • 29
  • 37
FearlessENT
  • 45
  • 2
  • 2
  • 9

4 Answers4

2

If I understood your question well, you want a "space" between the lines, and as some people already answered, \n is the choice.

For example, in the following code I place one \n to continue the text in the second line, and later I use \n\n to go to a new line twice, so I get a blank line separating the text:

>>> print('Hi, I am line number 1!\nI am line number two, nice to meet you!\n\nAnd I am line number 4, why is line number 3 so silent?')

Result:

Hi, I am line number 1!
I am line number two, nice to meet you!

And I am line number 4, why is line number 3 so silent?
Tom
  • 21
  • 6
0

If you want to accomplish this task, just use "\n".

print("Hello\nHow are you doing?") 

Result:

Hello
How are you doing?

Floern
  • 33,559
  • 24
  • 104
  • 119
jkl3699
  • 105
  • 8
-1

Just put a space in between the string argument of print.

print 'a' + ' ' + 'b' 

output: "a b"

LAL
  • 480
  • 5
  • 13
  • 1
    why not just print 'a b' ? or print '{0} {1}'.format('a', 'b') - the latter being for variables – Alan Kavanagh May 10 '16 at 18:01
  • True. I just wanted to show how to concatenate a space between variable. 'a' stands for anything. In this exemple it is a string type variable. – LAL May 11 '16 at 14:00
-3

If you meant a new line (vertical space) then the following works best.

print("\n")

The \n character can be placed anywhere in a string and will be interpreted as a new line.

wyattis
  • 1,287
  • 10
  • 21
  • That's actually print two newlines. One is your string, `"\n"`, the other is the newline added by `print` ... – NichtJens Jul 07 '16 at 00:36