#1865: document syntax for bytes literals.

This commit is contained in:
Georg Brandl 2010-09-25 13:46:23 +00:00
parent a0b6a49583
commit 7db964d5aa
1 changed files with 5 additions and 2 deletions

View File

@ -426,6 +426,7 @@ String literals are described by the following lexical definitions:
.. productionlist:: .. productionlist::
stringliteral: [`stringprefix`](`shortstring` | `longstring`) stringliteral: [`stringprefix`](`shortstring` | `longstring`)
stringprefix: "r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" | "uR" stringprefix: "r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" | "uR"
: | "b" | "B" | "br" | "Br" | "bR" | "BR"
shortstring: "'" `shortstringitem`* "'" | '"' `shortstringitem`* '"' shortstring: "'" `shortstringitem`* "'" | '"' `shortstringitem`* '"'
longstring: "'''" `longstringitem`* "'''" longstring: "'''" `longstringitem`* "'''"
: | '"""' `longstringitem`* '"""' : | '"""' `longstringitem`* '"""'
@ -458,8 +459,10 @@ different rules for interpreting backslash escape sequences. A prefix of
``'u'`` or ``'U'`` makes the string a Unicode string. Unicode strings use the ``'u'`` or ``'U'`` makes the string a Unicode string. Unicode strings use the
Unicode character set as defined by the Unicode Consortium and ISO 10646. Some Unicode character set as defined by the Unicode Consortium and ISO 10646. Some
additional escape sequences, described below, are available in Unicode strings. additional escape sequences, described below, are available in Unicode strings.
The two prefix characters may be combined; in this case, ``'u'`` must appear A prefix of ``'b'`` or ``'B'`` is ignored in Python 2; it indicates that the
before ``'r'``. literal should become a bytes literal in Python 3 (e.g. when code is
automatically converted with 2to3). A ``'u'`` or ``'b'`` prefix may be followed
by an ``'r'`` prefix.
In triple-quoted strings, unescaped newlines and quotes are allowed (and are In triple-quoted strings, unescaped newlines and quotes are allowed (and are
retained), except that three unescaped quotes in a row terminate the string. (A retained), except that three unescaped quotes in a row terminate the string. (A