typestar

Essential string methods in Python

The everyday toolkit for cleaning and probing text.

raw = "  The Quick Brown Fox  "

clean = raw.strip()
shout = clean.upper()
quiet = clean.lower()
title = quiet.title()

swapped = clean.replace("Quick", "Slow")
where = clean.find("Brown")

starts = clean.startswith("The")
ends = clean.endswith("Fox")
count_o = clean.count("o")

How it works

  1. strip removes surrounding whitespace.
  2. Case changes with upper, lower, and title.
  3. replace swaps substrings; find locates one.
  4. startswith, endswith, and count answer questions.

The run, in numbers

Lines
13
Characters to type
278
Tokens
87
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 61 seconds.

Type this snippet

Step 2 of 9 in Strings, step 8 of 72 in Language basics.

← Previous Next →