mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merged revisions 82373 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82373 | benjamin.peterson | 2010-06-29 10:57:57 -0500 (Tue, 29 Jun 2010) | 1 line note that byte strings can be raw, too #9114 ........
This commit is contained in:
parent
714b74d39f
commit
acf16deeb8
1 changed files with 9 additions and 9 deletions
|
@ -407,7 +407,7 @@ String literals are described by the following lexical definitions:
|
||||||
|
|
||||||
.. productionlist::
|
.. productionlist::
|
||||||
bytesliteral: `bytesprefix`(`shortbytes` | `longbytes`)
|
bytesliteral: `bytesprefix`(`shortbytes` | `longbytes`)
|
||||||
bytesprefix: "b" | "B"
|
bytesprefix: "b" | "B" | "br" | "Br" | "bR" | "BR"
|
||||||
shortbytes: "'" `shortbytesitem`* "'" | '"' `shortbytesitem`* '"'
|
shortbytes: "'" `shortbytesitem`* "'" | '"' `shortbytesitem`* '"'
|
||||||
longbytes: "'''" `longbytesitem`* "'''" | '"""' `longbytesitem`* '"""'
|
longbytes: "'''" `longbytesitem`* "'''" | '"""' `longbytesitem`* '"""'
|
||||||
shortbytesitem: `shortbyteschar` | `bytesescapeseq`
|
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
|
characters that otherwise have a special meaning, such as newline, backslash
|
||||||
itself, or the quote character.
|
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
|
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
|
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
|
may only contain ASCII characters; bytes with a numeric value of 128 or greater
|
||||||
must be expressed with escapes.
|
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
|
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
|
||||||
"quote" is the character used to open the string, i.e. either ``'`` or ``"``.)
|
"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
|
String literal concatenation
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
Multiple adjacent string literals (delimited by whitespace), possibly using
|
Multiple adjacent string or bytes literals (delimited by whitespace), possibly
|
||||||
different quoting conventions, are allowed, and their meaning is the same as
|
using different quoting conventions, are allowed, and their meaning is the same
|
||||||
their concatenation. Thus, ``"hello" 'world'`` is equivalent to
|
as their concatenation. Thus, ``"hello" 'world'`` is equivalent to
|
||||||
``"helloworld"``. This feature can be used to reduce the number of backslashes
|
``"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
|
needed, to split long strings conveniently across long lines, or even to add
|
||||||
comments to parts of strings, for example::
|
comments to parts of strings, for example::
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue