Search, case and checks
A method is a built-in action attached to a value, called with a dot: text.strip(). Strings have dozens, and about twenty cover almost everything: trimming, splitting and joining, replacing, searching, changing case, removing prefixes, and checking what a string contains.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Take name = " Ada Lovelace ". Make a clean lowercase version in clean, print it with repr, then print it in title case.
Turn the line "name,age,city" into name | age | city using split and join.
Given f = "photo.JPG", check that it is a JPEG regardless of case, and print its name without the extension.
Explain it without notes
Why does text.upper() on its own line not change text?
What is the difference between find and index, and between strip("ab") and removeprefix("ab")?
How do split and join relate, and what is special about split() with no argument?
When would you choose partition over split?
Expected output
find quick: 4
find slow: -1
count o: 2
starts with 'the': True
ends with '.py': True
one of two endings: True
THE QUICK BROWN FOX
The Quick Brown Fox
The quick brown fox
hELLO
casefold match: True
True True True True True
empty string isdigit: False