Skip to content

String processing

Strings are the format almost everything arrives in — log lines, CSV cells, user input, API responses. Python gives you a sharp set of tools for slicing them up, cleaning them, and building new ones, and most data work involves more string handling than you'd expect. This guide covers the methods, the formatting mini-language, and the gotchas.

Start here

If you're new to working with strings beyond the basics, work through the Learn section in order — four short notebooks, around fifteen minutes each. Every code cell can be edited and run in place, directly on the page; no install required.

If you already know the basics and are looking for a specific technique, jump to the Recipes section, or scan the Reference for the methods and format directives.

What this guide covers

Learn — string basics, the methods you'll use most, formatting with f-strings, and searching within strings.

Recipes — cleaning and normalising messy text, parsing structured strings, using templates, and the mistakes worth avoiding.

Reference — string methods, formatting mini-language, and the constants in string.

Concepts — why strings are immutable, and what Unicode and encodings are actually doing under the surface.