Skip to content

Commit c33f25e

Browse files
committed
Doc: Clarify newline escaping in triple-quoted strings (#160886)
Clarify that unescaped newlines are preserved in triple-quoted strings and that `"\<newline>"` omits them in non-raw string literals. Retain string literal concatenation as an alternative.
1 parent 87c0c35 commit c33f25e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎Doc/reference/lexical_analysis.rst‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,11 @@ A backslash can be added at the end of a line to ignore the newline::
838838
... backslashes or newline characters.'
839839
'This string will not include backslashes or newline characters.'
840840

841-
The same result can be achieved using :ref:`triple-quoted strings <strings>`,
842-
or parentheses and :ref:`string literal concatenation <string-concatenation>`.
841+
This escape sequence also works in non-raw :ref:`triple-quoted strings <strings>`,
842+
where unescaped newlines are otherwise preserved. It allows long string
843+
literals to be split across source lines without adding newline characters
844+
to the resulting string. Alternatively, the same result can be achieved
845+
using parentheses and :ref:`string literal concatenation <string-concatenation>`.
843846

844847
.. _string-escape-escaped-char:
845848

0 commit comments

Comments
 (0)