summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-05-16 15:32:28 (GMT)
committerGitHub <noreply@github.com>2022-05-16 15:32:28 (GMT)
commit4d05114ae74a5028c7d645a8257e18c5b9ddfa78 (patch)
treefb8275cef78d2ca673460bbb22ac18021e9859dd
parent14d05942ea21d4a95c9eac1f0bae53540d8f1602 (diff)
downloadcpython-4d05114ae74a5028c7d645a8257e18c5b9ddfa78.zip
cpython-4d05114ae74a5028c7d645a8257e18c5b9ddfa78.tar.gz
cpython-4d05114ae74a5028c7d645a8257e18c5b9ddfa78.tar.bz2
gh-80143: Add clarification for escape characters (GH-92292) (GH-92630)
(cherry picked from commit 549567c6e70da4846c105a18a1a89e7dd09680d7) Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
-rw-r--r--Doc/reference/lexical_analysis.rst10
1 files changed, 7 insertions, 3 deletions
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst
index 17c0fb4..b8f9ca2 100644
--- a/Doc/reference/lexical_analysis.rst
+++ b/Doc/reference/lexical_analysis.rst
@@ -447,9 +447,11 @@ see section :ref:`encodings`.
In plain English: Both types of literals can be enclosed in matching single quotes
(``'``) or double quotes (``"``). They can also be enclosed in matching groups
of three single or double quotes (these are generally referred to as
-*triple-quoted strings*). The backslash (``\``) character is used to escape
-characters that otherwise have a special meaning, such as newline, backslash
-itself, or the quote character.
+*triple-quoted strings*). The backslash (``\``) character is used to give special
+meaning to otherwise ordinary characters like ``n``, which means 'newline' when
+escaped (``\n``). It can also be used to escape characters that otherwise have a
+special meaning, such as newline, backslash itself, or the quote character.
+See :ref:`escape sequences <escape-sequences>` below for examples.
.. index::
single: b'; bytes literal
@@ -508,6 +510,8 @@ retained), except that three unescaped quotes in a row terminate the literal. (
single: \u; escape sequence
single: \U; escape sequence
+.. _escape-sequences:
+
Unless an ``'r'`` or ``'R'`` prefix is present, escape sequences in string and
bytes literals are interpreted according to rules similar to those used by
Standard C. The recognized escape sequences are: