×

python · level 1 · unit 3 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Strings come with tricks built in.

A is a trick a value knows how to do. Write the box name, a dot, then the method name and brackets. pet.upper() shouts in capitals and pet.lower() whispers in small letters.

.strip() trims spaces off both ends, handy when someone types an extra space. .replace("B", "W") swaps every B for a W, like a find-and-swap button.

is not a method, so it goes in front, like print. len(pet) counts every letter, space and symbol in the string.

pet = "Biscuit"
print(pet.upper())
print(pet.lower())
print(pet.replace("B", "W"))
print(len(pet))

A method gives back new text, and the box keeps its old value until you store the new one.