diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-06-29 15:57:57 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-06-29 15:57:57 (GMT) |
commit | 162dd7484e439c0552e17d09278301643f1b45f8 (patch) | |
tree | 7352b73e15bb8da44abc7fc9dfe25324f02eaddb /Doc/reference/lexical_analysis.rst | |
parent | ac16bdec5718b5c5a8809ee38631fe3579219858 (diff) | |
download | cpython-162dd7484e439c0552e17d09278301643f1b45f8.zip cpython-162dd7484e439c0552e17d09278301643f1b45f8.tar.gz cpython-162dd7484e439c0552e17d09278301643f1b45f8.tar.bz2 |
note that byte strings can be raw, too #9114
Diffstat (limited to 'Doc/reference/lexical_analysis.rst')
-rw-r--r-- | Doc/reference/lexical_analysis.rst | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 11b99f0..1b8b7b5 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -407,7 +407,7 @@ String literals are described by the following lexical definitions: .. productionlist:: bytesliteral: `bytesprefix`(`shortbytes` | `longbytes`) - bytesprefix: "b" | "B" + bytesprefix: "b" | "B" | "br" | "Br" | "bR" | "BR" shortbytes: "'" `shortbytesitem`* "'" | '"' `shortbytesitem`* '"' longbytes: "'''" `longbytesitem`* "'''" | '"""' `longbytesitem`* '"""' shortbytesitem: `shortbyteschar` | `bytesescapeseq` @@ -431,16 +431,16 @@ of three single or double quotes (these are generally referred to as characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. -String literals may optionally be prefixed with a letter ``'r'`` or ``'R'``; -such strings are called :dfn:`raw strings` and treat backslashes as literal -characters. As a result, ``'\U'`` and ``'\u'`` escapes in raw strings are not -treated specially. - Bytes literals are always prefixed with ``'b'`` or ``'B'``; they produce an instance of the :class:`bytes` type instead of the :class:`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 strings are called :dfn:`raw strings` and treat backslashes as +literal characters. As a result, in string literals, ``'\U'`` and ``'\u'`` +escapes in raw strings are not treated specially. + 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 "quote" is the character used to open the string, i.e. either ``'`` or ``"``.) @@ -545,9 +545,9 @@ characters as part of the string, *not* as a line continuation. String literal concatenation ---------------------------- -Multiple adjacent string literals (delimited by whitespace), possibly using -different quoting conventions, are allowed, and their meaning is the same as -their concatenation. Thus, ``"hello" 'world'`` is equivalent to +Multiple adjacent string or bytes literals (delimited by whitespace), possibly +using different quoting conventions, are allowed, and their meaning is the same +as their concatenation. Thus, ``"hello" 'world'`` is equivalent to ``"helloworld"``. This feature can be used to reduce the number of backslashes needed, to split long strings conveniently across long lines, or even to add comments to parts of strings, for example:: |