Python Strings · Question 4 · Easy
Which string method removes whitespace from both ends of a string?
- trim()
- rstrip()
- split()
- 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
- A city name is indexed from the front and from the back. What does this print?
- The length of a string is used to reach its last character. What is printed?
- Two case-changing methods are called on string literals. What is the output?
- The in operator tests two substrings of a city name. What does this print?
- An f-string is used to report Asha's marks. What exactly is printed?
- In the slice s[a:b] of a string s, with a less than b, which characters are…
- A slice with a step of 3 is taken from a city name. What does it print?
- replace() is called on a string and both the old and new names are printed…
- split() is called once with a comma separator and once with no argument. What…
- A list of integers is passed to join(). What happens when this runs?
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