String methods
Python · Unit 6: Strings
- Full plan
- Python
- 10 exercises
Strings come with methods, like append in lists: they go after a dot.
upper() makes it uppercase, lower() lowercase and strip() removes the spaces at the edges.
name = "Ann Parker"
print(name.upper())
print(name.lower())
print(" hi ".strip() + "!")Prints
ANN PARKER ann parker hi!
The rest of the explanation is in the lesson, which is part of the full plan.
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Predict the output
What does this code print?
2. Predict the output
What does this code print?
3. Complete the code
The person typed their name with extra spaces. Complete it to clean it up.
4. Predict the output
What does this code print?
5. Predict the output
What does this code print?
6. Find the bug
This program should print the email in lowercase, max@mail.com. Which line has the error?
7. Predict the output
What does this code print?
8. Multiple choice
What does
"hello".find("z")give?9. Complete the code
Complete the function so it says whether a file is a
.jpgphoto.10. Put the lines in order
Order the function that accepts "yes" even if the person types it with capitals or spaces.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.