Skip to content

Commit 3b96c51

Browse files
miss-islingtonslateny
authored andcommitted
pythongh-80143: Add clarification for escape characters (pythonGH-92292) (pythonGH-92630)
(cherry picked from commit 549567c) Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
1 parent 8d6958c commit 3b96c51

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
@@ -447,9 +447,11 @@ see section :ref:`encodings`.
447447
In plain English: Both types of literals can be enclosed in matching single quotes
448448
(``'``) or double quotes (``"``). They can also be enclosed in matching groups
449449
of three single or double quotes (these are generally referred to as
450-
*triple-quoted strings*). The backslash (``\``) character is used to escape
451-
characters that otherwise have a special meaning, such as newline, backslash
452-
itself, or the quote character.
450+
*triple-quoted strings*). The backslash (``\``) character is used to give special
451+
meaning to otherwise ordinary characters like ``n``, which means 'newline' when
452+
escaped (``\n``). It can also be used to escape characters that otherwise have a
453+
special meaning, such as newline, backslash itself, or the quote character.
454+
See :ref:`escape sequences <escape-sequences>` below for examples.
453455

454456
.. index::
455457
single: b'; bytes literal
@@ -508,6 +510,8 @@ retained), except that three unescaped quotes in a row terminate the literal. (
508510
single: \u; escape sequence
509511
single: \U; escape sequence
510512

513+
.. _escape-sequences:
514+
511515
Unless an ``'r'`` or ``'R'`` prefix is present, escape sequences in string and
512516
bytes literals are interpreted according to rules similar to those used by
513517
Standard C. The recognized escape sequences are:

0 commit comments

Comments
 (0)