Skip to content

Commit f51c232

Browse files
authored
[3.10] gh-95994: Clarify escaped newlines. (GH-96066) (#96360)
* gh-95994: clarify escaped newlines. * Rephrase ambiguous sentence. Co-authored-by: C.A.M. Gerlach <[email protected]> * Use `<newline>` in escape sequences table. Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]>. (cherry picked from commit c3d591f) Co-authored-by: Ezio Melotti <[email protected]>
1 parent 9b070d3 commit f51c232

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

Doc/reference/lexical_analysis.rst

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ Standard C. The recognized escape sequences are:
552552
+-----------------+---------------------------------+-------+
553553
| Escape Sequence | Meaning | Notes |
554554
+=================+=================================+=======+
555-
| ``\newline`` | Backslash and newline ignored | |
555+
| ``\``\ <newline>| Backslash and newline ignored | \(1) |
556556
+-----------------+---------------------------------+-------+
557557
| ``\\`` | Backslash (``\``) | |
558558
+-----------------+---------------------------------+-------+
@@ -574,48 +574,58 @@ Standard C. The recognized escape sequences are:
574574
+-----------------+---------------------------------+-------+
575575
| ``\v`` | ASCII Vertical Tab (VT) | |
576576
+-----------------+---------------------------------+-------+
577-
| ``\ooo`` | Character with octal value | (1,3) |
577+
| ``\ooo`` | Character with octal value | (2,4) |
578578
| | *ooo* | |
579579
+-----------------+---------------------------------+-------+
580-
| ``\xhh`` | Character with hex value *hh* | (2,3) |
580+
| ``\xhh`` | Character with hex value *hh* | (3,4) |
581581
+-----------------+---------------------------------+-------+
582582

583583
Escape sequences only recognized in string literals are:
584584

585585
+-----------------+---------------------------------+-------+
586586
| Escape Sequence | Meaning | Notes |
587587
+=================+=================================+=======+
588-
| ``\N{name}`` | Character named *name* in the | \(4) |
588+
| ``\N{name}`` | Character named *name* in the | \(5) |
589589
| | Unicode database | |
590590
+-----------------+---------------------------------+-------+
591-
| ``\uxxxx`` | Character with 16-bit hex value | \(5) |
591+
| ``\uxxxx`` | Character with 16-bit hex value | \(6) |
592592
| | *xxxx* | |
593593
+-----------------+---------------------------------+-------+
594-
| ``\Uxxxxxxxx`` | Character with 32-bit hex value | \(6) |
594+
| ``\Uxxxxxxxx`` | Character with 32-bit hex value | \(7) |
595595
| | *xxxxxxxx* | |
596596
+-----------------+---------------------------------+-------+
597597

598598
Notes:
599599

600600
(1)
601-
As in Standard C, up to three octal digits are accepted.
601+
A backslash can be added at the end of a line to ignore the newline::
602+
603+
>>> 'This string will not include \
604+
... backslashes or newline characters.'
605+
'This string will not include backslashes or newline characters.'
606+
607+
The same result can be achieved using :ref:`triple-quoted strings <strings>`,
608+
or parentheses and :ref:`string literal concatenation <string-concatenation>`.
602609

603610
(2)
604-
Unlike in Standard C, exactly two hex digits are required.
611+
As in Standard C, up to three octal digits are accepted.
605612

606613
(3)
614+
Unlike in Standard C, exactly two hex digits are required.
615+
616+
(4)
607617
In a bytes literal, hexadecimal and octal escapes denote the byte with the
608618
given value. In a string literal, these escapes denote a Unicode character
609619
with the given value.
610620

611-
(4)
621+
(5)
612622
.. versionchanged:: 3.3
613623
Support for name aliases [#]_ has been added.
614624

615-
(5)
625+
(6)
616626
Exactly four hex digits are required.
617627

618-
(6)
628+
(7)
619629
Any Unicode character can be encoded this way. Exactly eight hex digits
620630
are required.
621631

0 commit comments

Comments
 (0)