mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-80143: Add clarification for escape characters (GH-92292) (GH-92630)
(cherry picked from commit 549567c6e7
)
Co-authored-by: slateny <46876382+slateny@users.noreply.github.com>
This commit is contained in:
parent
14d05942ea
commit
4d05114ae7
1 changed files with 7 additions and 3 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue