You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The text about escaping newlines in triple-qouted strings is misleading #160886
A backslash can be added at the end of a line to ignore the newline:
(code sample)
The same result can be achieved using triple-quoted strings, or parentheses and string literal concatenation.
The current wording suggests that triple-quoted strings alone can split text across source lines without preserving newlines. In fact, unescaped newlines are retained, and omitting them requires the same backslash-newline escape used in ordinary string literals.
I suggest improving the text and clarifying that escaping newlines works the same in single- or triple-qouted string.
Unescaped newlines are also allowed and retained:
'''This triple-quoted string
continues on the next line.'''
The same result of ignoring newlines can be done with triple-quoted strings (with backslashes). However, "triple-quoted strings" in your quote above is linked to 2.5. String and Bytes literals rather than specifically to 2.5.1. Triple-quoted strings, where one finds the information you propose to duplicate, along with an example, and I think this link should be fixed. With this fix, I think the text is OK as is.
'string literal concatenation' is also linked, to 6.2.3.2. String literal concatenation, which has an example of parentheses and concatenation.
Thanks for reviewing this, Terry. I agree that the link should point to the triple-quoted strings subsection, and that my proposed explanation repeats information already covered there.
My remaining concern is that placing triple-quoted strings alongside string literal concatenation makes both sound like alternatives to using a backslash. A reader could therefore understand the sentence to mean that triple quotes alone remove the newline.
Would this shorter wording address that concern without repeating the earlier explanation?
“The same escape sequence can be used in triple-quoted strings. Alternatively, the same result can be achieved using parentheses and string literal concatenation.”
Activity
Doc: Clarify newline escaping in triple-quoted strings (python#160886)
Doc: Clarify newline escaping in triple-quoted strings (python#160886)
prodehghan commentedon Oct 29, 2026
Here is the PR: #160887
terryjreedy commentedon Oct 29, 2026
The earlier subsection 2.5.1. Triple-quoted strings already says
The same result of ignoring newlines can be done with triple-quoted strings (with backslashes). However, "triple-quoted strings" in your quote above is linked to
2.5. String and Bytes literalsrather than specifically to2.5.1. Triple-quoted strings, where one finds the information you propose to duplicate, along with an example, and I think this link should be fixed. With this fix, I think the text is OK as is.'string literal concatenation' is also linked, to
6.2.3.2. String literal concatenation, which has an example of parentheses and concatenation.Doc: Clarify newline escaping in triple-quoted strings (python#160886)
prodehghan commentedon Oct 29, 2026
Thanks for reviewing this, Terry. I agree that the link should point to the triple-quoted strings subsection, and that my proposed explanation repeats information already covered there.
My remaining concern is that placing triple-quoted strings alongside string literal concatenation makes both sound like alternatives to using a backslash. A reader could therefore understand the sentence to mean that triple quotes alone remove the newline.
Would this shorter wording address that concern without repeating the earlier explanation?
“The same escape sequence can be used in triple-quoted strings. Alternatively, the same result can be achieved using parentheses and string literal concatenation.”