Skip to content

Commit 549567c

Browse files
authored
gh-80143: Add clarification for escape characters (#92292)
1 parent 4e6da50 commit 549567c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Doc/reference/lexical_analysis.rst

Lines changed: 7 additions & 3 deletions
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)