Skip to content

Commit f0469c7

Browse files
gh-95994: Clarify escaped newlines. (GH-96066)
* 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 acd7841 commit f0469c7

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Doc/reference/lexical_analysis.rst

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ Standard C. The recognized escape sequences are:
548548
+-----------------+---------------------------------+-------+
549549
| Escape Sequence | Meaning | Notes |
550550
+=================+=================================+=======+
551-
| ``\newline`` | Backslash and newline ignored | |
551+
| ``\``\ <newline>| Backslash and newline ignored | \(1) |
552552
+-----------------+---------------------------------+-------+
553553
| ``\\`` | Backslash (``\``) | |
554554
+-----------------+---------------------------------+-------+
@@ -570,53 +570,64 @@ Standard C. The recognized escape sequences are:
570570
+-----------------+---------------------------------+-------+
571571
| ``\v`` | ASCII Vertical Tab (VT) | |
572572
+-----------------+---------------------------------+-------+
573-
| ``\ooo`` | Character with octal value | (1,3) |
573+
| ``\ooo`` | Character with octal value | (2,4) |
574574
| | *ooo* | |
575575
+-----------------+---------------------------------+-------+
576-
| ``\xhh`` | Character with hex value *hh* | (2,3) |
576+
| ``\xhh`` | Character with hex value *hh* | (3,4) |
577577
+-----------------+---------------------------------+-------+
578578

579579
Escape sequences only recognized in string literals are:
580580

581581
+-----------------+---------------------------------+-------+
582582
| Escape Sequence | Meaning | Notes |
583583
+=================+=================================+=======+
584-
| ``\N{name}`` | Character named *name* in the | \(4) |
584+
| ``\N{name}`` | Character named *name* in the | \(5) |
585585
| | Unicode database | |
586586
+-----------------+---------------------------------+-------+
587-
| ``\uxxxx`` | Character with 16-bit hex value | \(5) |
587+
| ``\uxxxx`` | Character with 16-bit hex value | \(6) |
588588
| | *xxxx* | |
589589
+-----------------+---------------------------------+-------+
590-
| ``\Uxxxxxxxx`` | Character with 32-bit hex value | \(6) |
590+
| ``\Uxxxxxxxx`` | Character with 32-bit hex value | \(7) |
591591
| | *xxxxxxxx* | |
592592
+-----------------+---------------------------------+-------+
593593

594594
Notes:
595595

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

599610
.. versionchanged:: 3.11
600611
Octal escapes with value larger than ``0o377`` produce a :exc:`DeprecationWarning`.
601612
In a future Python version they will be a :exc:`SyntaxWarning` and
602613
eventually a :exc:`SyntaxError`.
603614

604-
(2)
615+
(3)
605616
Unlike in Standard C, exactly two hex digits are required.
606617

607-
(3)
618+
(4)
608619
In a bytes literal, hexadecimal and octal escapes denote the byte with the
609620
given value. In a string literal, these escapes denote a Unicode character
610621
with the given value.
611622

612-
(4)
623+
(5)
613624
.. versionchanged:: 3.3
614625
Support for name aliases [#]_ has been added.
615626

616-
(5)
627+
(6)
617628
Exactly four hex digits are required.
618629

619-
(6)
630+
(7)
620631
Any Unicode character can be encoded this way. Exactly eight hex digits
621632
are required.
622633

0 commit comments

Comments
 (0)