Skip to content

[3.9] gh-80143: Add clarification for escape characters (GH-92292) #92630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Doc/reference/lexical_analysis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down