Whole document tree
|
Escape Sequence | Meaning |
---|---|
\newline |
Ignored |
\\ |
Backslash (\ ) |
\' |
Single quote (' ) |
\" |
Double quote (" ) |
\a |
ASCII Bell (BEL) |
\b |
ASCII Backspace (BS) |
\f |
ASCII Formfeed (FF) |
\n |
ASCII Linefeed (LF) |
\N{name} |
Character with 16-bit hex value xxxx (Unicode only) |
\r |
ASCII Carriage Return (CR) |
\t |
ASCII Horizontal Tab (TAB) |
\uxxxx |
Character with 32-bit hex value xxxxxxxx (Unicode only) |
\Uxxxxxxxx |
ASCII@ASCII |
\v |
ASCII Vertical Tab (VT) |
\ooo |
ASCII character with octal value ooo |
\xhh |
ASCII character with hex value hh |
As in Standard C, up to three octal digits are accepted. However, exactly two hex digits are taken in hex escapes.
Unlike Standard , all unrecognized escape sequences are left in the string unchanged, i.e., the backslash is left in the string. (This behavior is useful when debugging: if an escape sequence is mistyped, the resulting output is more easily recognized as broken.) It is also important to note that the escape sequences marked as ``(Unicode only)'' in the table above fall into the category of unrecognized escapes for non-Unicode string literals.
When an `r' or `R' prefix is present, a character following a
backslash is included in the string without change, and all
backslashes are left in the string. For example, the string literal
r"\n"
consists of two characters: a backslash and a lowercase
`n'. String quotes can be escaped with a backslash, but the backslash
remains in the string; for example, r"\""
is a valid string
literal consisting of two characters: a backslash and a double quote;
r"\"
is not a value string literal (even a raw string cannot
end in an odd number of backslashes). Specifically, a raw
string cannot end in a single backslash (since the backslash would
escape the following quote character). Note also that a single
backslash followed by a newline is interpreted as those two characters
as part of the string, not as a line continuation.
See About this document... for information on suggesting changes.