Python recognizes a full set of escape code sequences listed in the following table.
Escape | Meaning |
---|---|
\newline | Ignored (continuation line) |
\\ | Backslash (stores one \) |
\' | Single quote (stores ') |
\" | Double quote (stores ") |
\a | Bell |
\b | Backspace |
\f | Formfeed |
\n | Newline (linefeed) |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\xhh | Character with hex value hh (exactly 2 digits) |
\ooo | Character with octal value ooo (up to 3 digits) |
\0 | Null: binary 0 character (doesn't end string) |
\N{ id } | Unicode database ID |
\uhhhh | Unicode character with 16-bit hex value |
\Uhhhhhhhh | Unicode character with 32-bit hex value |
\other | Not an escape (keeps both \ and other) |
The \Uhhhh... escape sequence takes eight hexadecimal digits (h).
Both \u and \U are recognized only in Unicode string literals in 2.X.
They be used in normal Unicode strings in 3.X.
In a 3.X bytes literal, hexadecimal and octal escapes denote the byte.
In a string literal, these escapes denote a Unicode character with the given code-point value.