Use Special Characters In Python

by
Share this Article: Facebook92Google+0Twitter11LinkedIn0Reddit0StumbleUpon0

Sometimes, we want to add some extra space between two words, like pressing Tab key (which is identical up to 4x space-button length). In Python you have to make use of special characters in addition with a backslash (\). So for example:

print("Hello \tWorld")

Otherwise you can use concatenation using the + sign between strings, but this is not necessary. For example,

print("Hello" + "\t" + "world")

Both ways, will have the same result. This is the output:

Hello  World

Personally, I prefer the first way. It’s quicker, simpler and more close to C-style syntax.

For questions please refer to our Q/A forum at : http://ask.unixmen.com/

Share this Article: Facebook92Google+0Twitter11LinkedIn0Reddit0StumbleUpon0