Python Strip Exercises

Let’s check out some exercises that will help understand .strip() method better.

Exercise 4-a: Strip method to remove whitespace on both sides

Use strip method to strip the whitespaces on both sides of the string.


.strip() method will strip specified character(s) from the string it’s applied to.

str = str.strip(" ")

Exercise 4-b: Strip method to remove specific characters from a string

Using .strip() method, strip the string so that, only "Babylon" remains.


.strip() method can take multiple characters and it will strip all of the matching characters from both sides of the string.

str = str.strip("#$^&@% ")