Ask me what my Python does on an ordinary day and the answer isn't clever algorithms. It's pulling a field out of a log line, cleaning up a filename, gluing a URL back together. A small set of string methods does almost all of that work, and they're worth knowing the way you know keyboard shortcuts — without thinking. These are the ones I reach for before breakfast.
Input is dirty. Copy-pasted values arrive with spaces, files arrive with trailing newlines, and half of my early parsing bugs were just that. strip() removes whitespace from both ends:
raw = " backup done \n"
print(repr(raw.strip())) # 'backup done'
(There are lstrip() and rstrip() for one-sided jobs, but I use the two-sided one nine times out of ten.)
My most common move in any script is splitting a line at its separator. Given a log entry, split(",") hands back the fields:
entry = "2026-06-18 09:14,backup,ok"
stamp, job, status = entry.split(",")
print(stamp, status) # 2026-06-18 09:14 ok
messy = " too many spaces "
print(messy.split()) # ['too', 'many', 'spaces']
split(",") splits on exactly that separator. split() with no argument splits on any run of whitespace, which is how I count words and untangle messy spacing.
join turns a list back into a single string, and the glue is the string you call it on:
parts = ["192", "168", "1", "1"]
print(".".join(parts)) # 192.168.1.1
flags = ["read", "write", "execute"]
print(" | ".join(flags)) # read | write | execute
The call lives on the separator, not the list — ["192", "168"].join(".") gives an AttributeError. Every beginner writes it backwards exactly once; that's the tuition.
For filenames and slugs I chain the small ones. Each method returns a new string, so a chain reads left to right like a pipeline:
title = " The Art of Naming Things (2nd Ed.) "
slug = title.strip().lower().replace(" ", "-")
print(slug) # the-art-of-naming-things-(2nd-ed.)
Strip first, then lowercase, then swap spaces for dashes. I read chains out loud as steps: trim it, lowercase it, dash it.
Python has three ways to format strings: %-style, str.format(), and f-strings. My honest advice is to learn f-strings and let the other two find you in old code later. An f-string is any string with an f before the quote, and variables go straight into the braces:
name = "backup"
seconds = 3.2719
files = 1280
print(f"{name} finished in {seconds:.1f}s") # backup finished in 3.3s
print(f"{name}: {files:,} files") # backup: 1,280 files
The bits after the colon are mini-instructions: .1f means one decimal place, the comma adds thousands separators. That's ninety percent of the formatting I ever need, and it stays attached to the value it formats, where I can see it.
If a string problem looks hard, it's usually because I picked the wrong separator: split at the right spot, strip the leftovers, join it back when needed. Three verbs and an f-string have carried most of the text work I've ever done.