The text about escaping newlines in triple-qouted strings is misleading

Aperta
#160,886 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
1/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Read section 2.5.4.1 of the lexical analysis documentation at docs.python.org/3.16/reference/lexical_analysis.html#string-escape-ignore. Clarify that unescaped newlines in triple-quoted strings are retained and that omitting a newline requires a backslash-newline escape in both single- and triple-quoted strings. Check the wording against the examples in that section; the issue says the reporter is creating a PR and lists linked PR #160887.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

docs
Documentation

File: https://docs.python.org/3.16/reference/lexical_analysis.html#string-escape-ignore
Section 2.5.4.1 says:

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.

I'm creating the PR.

Linked PRs
  • gh-160887
Lingua principale
Python
Stelle
77.8k
Fork
37.7k
Merge medio
15h 24m
PR unite (30g)
728

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.