Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print spaces in Python?

Tags:

python

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!

like image 589
Justin Chiang Avatar asked Sep 16 '12 21:09

Justin Chiang


People also ask

How do you print spaces in Python?

To give multiple spaces between two values, we can assign space in a variable, and using the variable by multiplying the value with the required spaces. For example, there is a variable space assigned with space and we need to print 5 spaces - we can use space*5 and it will print the 5 spaces.

How do I print a space between lines in Python?

You have a few solutions: The simpler one would be to use a print statement between your lines, which, used alone, prints a line feed. Alternatively, you could you end the string you're printing with a '\n' character, which will cause a line feed, or you could start your input with the same character.

How do you do a space in Python?

Spacing in Python language is quite simple than other programming language. In C languages, to print 10 spaces a loop is used while in python no loop is used to print number of spaces.

How do I see spaces in Python?

Python String isspace() The isspace() method returns True if there are only whitespace characters in the string. If not, it return False. Characters that are used for spacing are called whitespace characters. For example: tabs, spaces, newline, etc.


2 Answers

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 and World

print(f"Hello{x*10}World")
like image 143
RL-Perf Avatar answered Oct 11 '22 11:10

RL-Perf


print("hello" + ' '*50 + "world")

like image 39
Arvind Reddy Avatar answered Oct 11 '22 11:10

Arvind Reddy