Skip to the content

String methods

Python · Unit 6: Strings

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. 1. Predict the output

    What does this code print?

  2. 2. Predict the output

    What does this code print?

  3. 3. Complete the code

    The person typed their name with extra spaces. Complete it to clean it up.

  4. 4. Predict the output

    What does this code print?

  5. 5. Predict the output

    What does this code print?

  6. 6. Find the bug

    This program should print the email in lowercase, max@mail.com. Which line has the error?

  7. 7. Predict the output

    What does this code print?

  8. 8. Multiple choice

    What does "hello".find("z") give?

  9. 9. Complete the code

    Complete the function so it says whether a file is a .jpg photo.

  10. 10. Put the lines in order

    Order the function that accepts "yes" even if the person types it with capitals or spaces.

Do this lesson

It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.

See all lessons →