Improve your skills with Exercise 4: .strip() method | HolyPython.com
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.
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("#$^&@% ")Exercise 4-c: Rstrip method to remove from the right side only
Let's say you created a program that crawls websites online and it returned a string with a bunch of unnecessary characters on the right side. Using .rstrip() method, strip the characters from the right side of the string only so, in the end you get: "@Bloomberg"
.rstrip() will only strip the right side of a string.
Need More Exercises?
Check out Holy Python AI+ for amazing Python learning tools.
*Includes 14 more programming languages, inspirational tools and 1-on-1 consulting options.

Umut Sagir
Finance & Data Science Professional,
Founder of HolyPython