python · level 1 · unit 3 · lesson 3
- meet it
- guess first
- your turn
- fix it
- 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.
guess first
How long is an ice cream? Make a guess.
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
snack = "ice cream"
print(len(snack))
your turn
Your turn. Shout about your favourite food.
Type your favourite food between the quotes. Python will shout it, then count it.
fix it
Why is it still whispering? Make it shout.
- Line 2 makes a shouty copy, but nothing keeps hold of it.
- A method gives back new text. Store it in the box again, the way you overwrite a variable.
- Change line 2 to
shout = shout.upper(), then press run.
nailed it
your strings can do tricks now. :D
- A method goes after a dot, like
name.upper(). len()counts every letter, space and symbol.- Methods give back new text, so store it to keep it.
new words in your collection
- method
- len
This lesson isn’t saved. A free account remembers every lesson you finish.