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!
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.
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.
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.
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.
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")
print("hello" + ' '*50 + "world")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With