gh-80143: Add clarification for escape characters (GH-92292) (GH-92629)

(cherry picked from commit 549567c6e7)

Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2022-05-16 09:54:40 -07:00 committed by GitHub
parent e29ce9a5f1
commit 006b302beb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 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 (``'``) or double quotes (``"``). They can also be enclosed in matching groups
of three single or double quotes (these are generally referred to as of three single or double quotes (these are generally referred to as
*triple-quoted strings*). The backslash (``\``) character is used to escape *triple-quoted strings*). The backslash (``\``) character is used to give special
characters that otherwise have a special meaning, such as newline, backslash meaning to otherwise ordinary characters like ``n``, which means 'newline' when
itself, or the quote character. 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:: .. index::
single: b'; bytes literal 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
single: \U; escape sequence single: \U; escape sequence
.. _escape-sequences:
Unless an ``'r'`` or ``'R'`` prefix is present, escape sequences in string and 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 bytes literals are interpreted according to rules similar to those used by
Standard C. The recognized escape sequences are: Standard C. The recognized escape sequences are: