Python - Special Characters

In Python, the speciall characters can used in strings/messages.
The special characters can used escape character( \ backslash) to insert in string.

Special Characters

Special Character Name
\n New Line
\t Horizantal Tab
\r Carriage Return
\b Backspace
\f Form feed
\' Single quote
\" Double quote
\\ Backslash
\v Vertical tab
\N N is the number for Unicode character
\NNN NNN are the digits for Octal Value
\xHH HH is the hex value, x denotes that it is a hex value


Usage of Special characters in String

You can use special characters in string when we need them based on the purpose. You can find usage of special characters below.

    # String with special character \n
    print("Awesome\nPython")
    
    Output:Awesome
    Python
    # String with special character \t
    print("Awesome\tPython")

    Output: Awesome  Python
    # String with special character \r
    print("Awesome\rPython")

    Output: Pythone 
    # String with special character \b
    print("Awesome\bPython")

    Output: AwesomPython
    # String with special character \f
    print("Awesome\fPython")

    Output: Awesome
                    Python
    # String with special character \"
    print("Awesome \"Python\"")

    Output: Awesome "Python"
    # String with special character \'
    print("Awesome \'Python\'")

    Output: Awesome 'Python'


Related Tutorials