Use Special Characters In Python

Use Special Characters In Python

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.

  • setevoй червь™

    As for me – second example more readable… But – need more characters, yes :-)

  • Panos Georgiadis

    Google for Escape Sequences or follow this link:

  • setevoй червь™

    Thanks, I know what it is… But I mean exactly “redable”, like “more simple to read for eyes”.