How to print spaces in Python?

6

In C++, \n is used, but what do I use in Python?

I don't want to have to use: print (" "). This doesn't seem very elegant.

Any help will be greatly appreciated!

This question is tagged with python

~ Asked on 2012-09-16 21:02:11

The Best Answer is


14

Here's a short answer

x=' ';

This will print one white space

print(x); 

This will print 10 white spaces

print(10*x) 

Print 10 whites spaces between Hello & World

print("Hello"+10*x+"world"); 

~ Answered on 2015-10-29 21:25:34


7

If you need to separate certain elements with spaces you could do something like

print "hello", "there"

Notice the comma between "hello" and "there".

If you want to print a new line (i.e. \n) you could just use print without any arguments.

~ Answered on 2012-09-16 21:04:58


Most Viewed Questions: