We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
.strip() is a string method that by default removes any whitespace from either side of the whole string. e.g.
" hello there ".strip()
becomes "hello there"
If you add an argument, it will instead remove whatever characters you put as the argument from either side of the string (not the middle). You will often see it used like this, to clean up words after using .split():
Python If-Else
You are viewing a single comment's thread. Return to all comments →
.strip() is a string method that by default removes any whitespace from either side of the whole string. e.g.
becomes "hello there"
If you add an argument, it will instead remove whatever characters you put as the argument from either side of the string (not the middle). You will often see it used like this, to clean up words after using .split():