Python Strings · Question 4 · Easy

Which string method removes whitespace from both ends of a string?

  1. trim()
  2. rstrip()
  3. split()
  4. strip()
Answer and explanation

Answer: D. strip()

Explanation: strip() returns a copy without leading and trailing whitespace. rstrip() removes only from the right end, split() breaks the string into a list, and trim() is a Java method that does not exist in Python.

Previous: Two case-changing methods are called on string literals. What is the output? · Next: The in operator tests two substrings of a city name. What does this print?

Practise python strings

Try a fresh set of python strings questions with an explanation after every answer, free and without signing up: Python Strings practice. Or sit a full placement mock test.

More python strings questions

More python practice

Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge