Skip to content

Commit 006b302

Browse files
gh-80143: Add clarification for escape characters (GH-92292) (GH-92629)
(cherry picked from commit 549567c) Co-authored-by: slateny <[email protected]>
1 parent e29ce9a commit 006b302

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Doc/reference/lexical_analysis.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,11 @@ declaration is given in the source file; see section :ref:`encodings`.
480480
In plain English: Both types of literals can be enclosed in matching single quotes
481481
(``'``) or double quotes (``"``). They can also be enclosed in matching groups
482482
of three single or double quotes (these are generally referred to as
483-
*triple-quoted strings*). The backslash (``\``) character is used to escape
484-
characters that otherwise have a special meaning, such as newline, backslash
485-
itself, or the quote character.
483+
*triple-quoted strings*). The backslash (``\``) character is used to give special
484+
meaning to otherwise ordinary characters like ``n``, which means 'newline' when
485+
escaped (``\n``). It can also be used to escape characters that otherwise have a
486+
special meaning, such as newline, backslash itself, or the quote character.
487+
See :ref:`escape sequences <escape-sequences>` below for examples.
486488

487489
.. index::
488490
single: b'; bytes literal
@@ -541,6 +543,8 @@ retained), except that three unescaped quotes in a row terminate the literal. (
541543
single: \u; escape sequence
542544
single: \U; escape sequence
543545

546+
.. _escape-sequences:
547+
544548
Unless an ``'r'`` or ``'R'`` prefix is present, escape sequences in string and
545549
bytes literals are interpreted according to rules similar to those used by
546550
Standard C. The recognized escape sequences are:

0 commit comments

Comments
 (0)