y the following lexical definitions: stringliteral ::= [stringprefix](shortstring | longstring) stringprefix ::= "r" | "u" | "R" | "U" | "f" | "F" | "fr" | "Fr" | "fR" | "FR" | "rf" | "rF" | "Rf" | "RF" shortstring ::= "'" shortstringitem* "'" | '"' shortstringitem* '"' longstring ::= "'''" longstringitem* "'''" | '"""' longstringitem* '"""' shortstringitem ::= shortstringchar | stringescapeseq longstringitem ::= longstringchar | stringescapeseq shortstringchar ::= longstringchar ::= stringescapeseq ::= "\" bytesliteral ::= bytesprefix(shortbytes | longbytes) bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR" | "rb" | "rB" | "Rb" | "RB" shortbytes ::= "'" shortbytesitem* "'" | '"' shortbytesitem* '"' longbytes ::= "'''" longbytesitem* "'''" | '"""' longbytesitem* '"""' shortbytesitem ::= shortbyteschar | bytesescapeseq longbytesitem ::= longbyteschar | bytesescapeseq shortbyteschar ::= longbyteschar ::= bytesescapeseq ::= "\" One syntactic restriction not indicated by these productions is that whitespace is not allowed between the "stringprefix" or "bytesprefix" and the rest of the literal. The source character set is defined by the encoding declaration; it is UTF-8 if no encoding declaration is given in the source file; see section Encoding declarations. In plain English: Both types of literals can be enclosed in matching single quotes ("'") or double quotes ("""). They can also be enclosed in matching groups of three single or double quotes (these are generally referred to as *triple-quoted strings*). The backslash ("\") character is used to give special meaning to otherwise ordinary characters like "n", which means ‘newline’ when escaped ("\n"). It can also be used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. See escape sequences below for examples. Bytes literals are always prefixed with "'b'" or "'B'"; they produce an instance of the "bytes" type instead of the "str" type. They may only contain ASCII characters; bytes with a numeric value of 128 or greater must be expressed with escapes. Both string and bytes literals may optionally be prefixed with a letter "'r'" or "'R'"; such constructs are called *raw string literals* and *raw bytes literals* respectively and treat backslashes as literal characters. As a result, in raw string literals, "'\U'" and "'\u'" escapes are not treated specially. Added in version 3.3: The "'rb'" prefix of raw bytes literals has been added as a synonym of "'br'".Support for the unicode legacy literal ("u'value'") was reintroduced to simplify the maintenance of dual Python 2.x and 3.x codebases. See **PEP 414** for more information. A string literal with "'f'" or "'F'" in its prefix is a *formatted string literal*; see f-strings. The "'f'" may be combined with "'r'", but not with "'b'" or "'u'", therefore raw formatted strings are possible, but formatted bytes literals are not. In triple-quoted literals, unescaped newlines and quotes are allowed (and are retained), except that three unescaped quotes in a row terminate the literal. (A “quote” is the character used to open the literal, i.e. either "'" or """.) Escape sequences ================ Unless an "'r'" or "'R'" prefix is present, escape sequences in string and bytes literals are interpreted according to rules similar to those used by Standard C. The recognized escape sequences are: +---------------------------+-----------------------------------+---------+ | Escape Sequence | Meaning | Notes | |===========================|===================================|=========| | "\" | Backslash and newline ignored | (1) | +---------------------------+-----------------------------------+---------+ | "\\" | Backslash ("\") | | +---------------------------+-----------------------------------+---------+ | "\'" | Single quote ("'") | | +---------------------------+-----------------------------------+---------+ | "\"" | Double quote (""") | | +---------------------------+-----------------------------------+---------+ | "\a" | ASCII Bell (BEL) | | +---------------------------+-----------------------------------+---------+ | "\b" | ASCII Backspace (BS) | | +---------------------------+-----------------------------------+---------+ | "\f" | ASCII Formfeed (FF) | | +---------------------------+-----------------------------------+---------+ | "\n" | ASCII Linefeed (LF) | | +---------------------------+-----------------------------------+---------+ | "\r" | ASCII Carriage Return (CR) | | +---------------------------+-----------------------------------+---------+ | "\t" | ASCII Horizontal Tab (TAB) | | +---------------------------+-----------------------------------+---------+ | "\v" | ASCII Vertical Tab (VT) | | +---------------------------+-----------------------------------+---------+ | "\*ooo*" | Character with octal value *ooo* | (2,4) | +---------------------------+-----------------------------------+---------+ | "\x*hh*" | Character with hex value *hh* | (3,4) | +---------------------------+-----------------------------------+---------+ Escape sequences only recognized in string literals are: +---------------------------+-----------------------------------+---------+ | Escape Sequence | Meaning | Notes | |===========================|===================================|=========| | "\N{*name*}" | Character named *name* in the | (5) | | | Unicode database | | +---------------------------+-----------------------------------+---------+ | "\u*xxxx*" | Character with 16-bit hex value | (6) | | | *xxxx* | | +---------------------------+-----------------------------------+---------+ | "\U*xxxxxxxx*" | Character with 32-bit hex value | (7) | | | *xxxxxxxx* | | +---------------------------+-----------------------------------+---------+ Notes: 1. A backslash can be added at the end of a line to ignore the newline: >>> 'This string will not include \ ... backslashes or newline characters.' 'This string will not include backslashes or newline characters.' The same result can be achieved using triple-quoted strings, or parentheses and string literal concatenation. 2. As in Standard C, up to three octal digits are accepted. Changed in version 3.11: Octal escapes with value larger than "0o377" produce a "DeprecationWarning". Changed in version 3.12: Octal escapes with value larger than "0o377" produce a "SyntaxWarning". In a future Python version they will be eventually a "SyntaxError". 3. Unlike in Standard C, exactly two hex digits are required. 4. In a bytes literal, hexadecimal and octal escapes denote the byte with the given value. In a string literal, these escapes denote a Unicode character with the given value. 5. Changed in version 3.3: Support for name aliases [1] has been added. 6. Exactly four hex digits are required. 7. Any Unicode character can be encoded this way. Exactly eight hex digits are required. Unlike Standard C, all unrecognized escape sequences are left in the string unchanged, i.e., *the backslash is left in the result*. (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 only recognized in string literals fall into the category of unrecognized escapes for bytes literals. Changed in version 3.6: Unrecognized escape sequences produce a "DeprecationWarning". Changed in version 3.12: Unrecognized escape sequences produce a "SyntaxWarning". In a future Python version they will be eventually a "SyntaxError". Even in a raw literal, quotes can be escaped with a backslash, but the backslash remains in the result; for example, "r"\""" is a valid string literal consisting of two characters: a backslash and a double quote; "r"\"" is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, *a raw literal 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 literal, *not* as a line continuation. subscriptionsu(