1. Concept library
  2. Python Foundations
  3. Module 6: Strings and formatting

Concept

String methods

Strings cannot be changed, so every method returns a new string: strip, lower, replace, startswith, find. Chaining them cleans input in one readable line.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain why string methods return a new string instead of changing the old one
  2. Clean a line of user input with strip, lower and replace in one chain
  3. Use startswith, find and in to check for text inside a string

In practice

A few lines that show String methods doing its job.

Python
raw = "  Ada.Lovelace@Example.com \n"
email = raw.strip().lower()

print(email)                          # ada.lovelace@example.com
print(email.endswith("@example.com")) # True
print(email.replace(".", " "))
print("Error: disk".startswith("Error"))

The common mistake

Watch for

Calling name.strip() and expecting name to change. The original is untouched; you must keep the returned value, as in name = name.strip().

What to know first

Your roadmap puts these before String methods, unless you already know them.

How it stays learned

Once a session shows you understand String methods, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on String methods.

Next in the modulef-strings →