Recipes: String processing¶
Short, task-focused how-tos for the string-handling jobs that come up over and over. Each recipe assumes you already know the basics — if a method surprises you, the Learn section is one click away.
Unlike the tutorials, the recipes don't have a recommended order. Pick whichever is useful right now.
Recipes in this guide¶
- Clean and normalise text — stripping whitespace, fixing case, normalising Unicode, and handling the rough edges of real-world text.
- Parse structured strings — splitting key-value pairs, dotted paths, and other lightly structured input without reaching for a parser.
- Use string templates —
string.Templatefor safer user-facing substitution, and when to prefer it over f-strings. - Avoid common string mistakes — silent encoding bugs, mutability surprises, and the methods people misuse.