Use Special Characters In Python


Please shareShare on Facebook0Share on Google+1Tweet about this on Twitter11Share on LinkedIn0Share on Reddit0Digg thisShare on StumbleUpon1Share on VKBuffer this page

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.