Python 3 Escape Sequences

List of escape sequences available in Python 3.

Escape Sequence Description Example
\newline Backslash and newline ignored
Result
line1 line2 line3
\\ Backslash (\)
Result
\
\' Single quote (')
Result
'
\" Double quote (")
Result
"
\a ASCII Bell (BEL)
\b ASCII Backspace (BS)
Result
Hello  World!
\f ASCII Formfeed (FF)
Result
Hello 
 World!
\n ASCII Linefeed (LF)
Result
Hello 
 World!
\r ASCII Carriage Return (CR)
Result
Hello 
 World!
\t ASCII Horizontal Tab (TAB)
Result
Hello      World!
\v ASCII Vertical Tab (VT)
Result
Hello 
 World!
\ooo Character with octal value ooo
Result
Hello World!
\xhh Character with hex value hh
Result
Hello World!

Some escape sequences are only recognized in string literals. These are:

Escape Sequence Description
\N{name} Character named name in the Unicode database
\uxxxx Character with 16-bit hex value xxxx. Exactly four hexadecimal digits are required.
\Uxxxxxxxx Character with 32-bit hex value xxxxxxxx. Exactly eight hexadecimal digits are required.