Find-and-replace across many lines
P42.from-paper-to-notebook.03 · Audience: guest, language-pro, it-ml · Prerequisites: Build a vocabulary table
A term was renamed, a client became a customer, a spelling was standardised —
and now it must change everywhere. In a document you would scroll through and fix
each line by hand, hoping to miss none. The notebook applies the one rule to the
whole list at once: a loop over the lines and .replace on each.
ⓘ Concept: .replace hands back a fixed copy
line.replace(OLD, NEW) returns a new string with every OLD swapped for NEW. The original line is left exactly as it was — replace hands you a fresh copy rather than editing in place, so nothing is lost.Why it matters — Knowing that replace returns a new string — and never touches the original — is what makes it safe to run across a whole document.
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
🎓 Practice ladder
1 graded rung · ~6 minYour turn: loop over the lines and build a new list with the old word replaced by the new one on every line. Press Run.
Explorer rung — find-and-replace across lines
Loading exercise…
Where next?
Later in From Paper to Notebook