Answer key · 12 questions

Python String Methods Exercises With Answers

All 12 questions for Python String Methods in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python String Methods, with the exact answer and a short explanation for every question.

The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.

01 · Multiple choice

What does strip() remove from a string?

  1. Only commas
  2. All spaces everywhere
  3. Only uppercase letters
  4. Whitespace from both endscorrect

Answer: Whitespace from both ends

Why: strip() removes leading and trailing whitespace by default.

02 · Multiple choice

What is the result of "Latte".lower()?

  1. latte
  2. Latte
  3. lattecorrect
  4. LATTE

Answer: latte

Why: lower() returns a copy with all letters in lowercase.

03 · Multiple choice

What does "a,b,c".split(",") return?

  1. A tuple of two strings
  2. A single string
  3. A list of three stringscorrect
  4. An integer

Answer: A list of three strings

Why: split returns a list containing the fields between separators.

04 · Multiple choice

What is the result of "-".join(["a", "b"])?

  1. a b
  2. a-bcorrect
  3. ['a', 'b']
  4. ab

Answer: a-b

Why: join places the separator string between each item.

05 · Fill in the blank

Complete the method that removes spaces from both ends.

text = "  latte  "
print(text.____())

Answer: strip

Why: strip() removes leading and trailing whitespace.

06 · Fill in the blank

Complete the method so PYTHON becomes python.

print("PYTHON".____())

Answer: lower

Why: lower() returns a lowercase copy of the string.

07 · Fill in the blank

Complete the method that splits the text at each comma.

print("a,b".____(","))

Answer: split

Why: split(separator) breaks a string into a list.

08 · Fill in the blank

Complete the method that joins the two words with a space.

print(" ".____(["hello", "world"]))

Answer: join

Why: The separator string calls join with an iterable of strings.

09 · Predict output

What appears on the screen?

print("  latte  ".strip())

Answer: latte

Why: strip removes the spaces at both ends.

10 · Predict output

What is printed?

print("Python".lower())

Answer: python

Why: lower converts every letter to lowercase.

11 · Predict output

What is the output?

print("a,b,c".split(","))

Answer: ['a', 'b', 'c']

Why: split returns a list of the three fields.

12 · Predict output

What does this code print?

print("-".join(["a", "b", "c"]))

Answer: a-b-c

Why: join inserts a hyphen between each item.

Try the questions first

Open the practice page for Python String Methods and answer the same 12 questions with instant feedback.

Practice this lesson