From b7be67b89ed94604efa39f8ab5c4fa0c244a8a52 Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Tue, 3 May 2022 23:30:11 -0700 Subject: [PATCH 1/2] Add clarification for escape characters --- Doc/reference/lexical_analysis.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 0e64a056a6eb20..cf424fe0af0647 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -482,7 +482,9 @@ In plain English: Both types of literals can be enclosed in matching single quot 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. +itself, or the quote character. It can also be used to give special meaning to +otherwise ordinary characters like ``n``, which means 'newline' when escaped +(``\n``). See :ref:`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: From c5d6bfa168d1e10e3a240aaab0ee4030eda014f1 Mon Sep 17 00:00:00 2001 From: slateny <46876382+slateny@users.noreply.github.com> Date: Wed, 4 May 2022 20:05:55 -0700 Subject: [PATCH 2/2] Reorder sentences --- Doc/reference/lexical_analysis.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index cf424fe0af0647..1cf0a5b15cbbb9 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -480,11 +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. It can also be used to give special meaning to -otherwise ordinary characters like ``n``, which means 'newline' when escaped -(``\n``). See :ref:`escape sequences ` below for examples. +*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 ` below for examples. .. index:: single: b'; bytes literal