← Back to DAGDA | Support | Source: https://github.com/python/cpython/commit/50364b4a5c8f02ec05d33928e29a8780d9acf968
Skip to content

Commit 50364b4

Browse files
committed
Basic documentation for PEP 414
1 parent 6ecf77b commit 50364b4

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎Doc/reference/lexical_analysis.rst‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ String literals are described by the following lexical definitions:
401401

402402
.. productionlist::
403403
stringliteral: [`stringprefix`](`shortstring` | `longstring`)
404-
stringprefix: "r" | "R"
404+
stringprefix: "r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" | "uR"
405405
shortstring: "'" `shortstringitem`* "'" | '"' `shortstringitem`* '"'
406406
longstring: "'''" `longstringitem`* "'''" | '"""' `longstringitem`* '"""'
407407
shortstringitem: `shortstringchar` | `stringescapeseq`
@@ -441,6 +441,9 @@ instance of the :class:`bytes` type instead of the :class:`str` type. They
441441
may only contain ASCII characters; bytes with a numeric value of 128 or greater
442442
must be expressed with escapes.
443443

444+
As of Python 3.3 it is possible again to prefix unicode strings with a
445+
``u`` prefix to simplify maintenance of dual 2.x and 3.x codebases.
446+
444447
Both string and bytes literals may optionally be prefixed with a letter ``'r'``
445448
or ``'R'``; such strings are called :dfn:`raw strings` and treat backslashes as
446449
literal characters. As a result, in string literals, ``'\U'`` and ``'\u'``
@@ -450,6 +453,11 @@ escapes in raw strings are not treated specially.
450453
The ``'rb'`` prefix of raw bytes literals has been added as a synonym
451454
of ``'br'``.
452455

456+
.. versionadded:: 3.3
457+
Support for the unicode legacy literal (``u'value'``) and other
458+
versions were reintroduced to simplify the maintenance of dual
459+
Python 2.x and 3.x codebases. See :pep:`414` for more information.
460+
453461
In triple-quoted strings, unescaped newlines and quotes are allowed (and are
454462
retained), except that three unescaped quotes in a row terminate the string. (A
455463
"quote" is the character used to open the string, i.e. either ``'`` or ``"``.)

0 commit comments

Comments
 (0)