diff options
author | slateny <46876382+slateny@users.noreply.github.com> | 2022-05-10 16:12:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-10 16:12:29 (GMT) |
commit | 549567c6e70da4846c105a18a1a89e7dd09680d7 (patch) | |
tree | 0835556b05f9803d3d0a2753ea70bb94a4e41485 /Doc | |
parent | 4e6da502f42e3cbdffbe850833d2b04996232f0d (diff) | |
download | cpython-549567c6e70da4846c105a18a1a89e7dd09680d7.zip cpython-549567c6e70da4846c105a18a1a89e7dd09680d7.tar.gz cpython-549567c6e70da4846c105a18a1a89e7dd09680d7.tar.bz2 |
gh-80143: Add clarification for escape characters (#92292)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/reference/lexical_analysis.rst | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 0e64a05..1cf0a5b 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -480,9 +480,11 @@ declaration is given in the source file; 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 @@ -541,6 +543,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: |