Python Quest

Track 7 · Lesson 2 of 11

Cleaning messy text

Tidy user-entered text with the strip family, case methods, replace, removeprefix and whitespace normalisation.

About 35 minBeginner4 exercises

You will be able to

  • Remove unwanted characters from the ends of a string with strip(), lstrip() and rstrip()
  • Remove a known prefix or suffix safely with removeprefix() and removesuffix()
  • Change case with lower(), upper(), title() and capitalize(), and know where title() goes wrong
  • Replace text with replace(), including a limited number of replacements
  • Collapse runs of spaces, tabs and newlines into single spaces with split() and join()

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.