strip( ) Function
The strip( ) Function is used to remove any unwanted character from the String with Space by default.
x = " Hello " y = x.strip() print(y)
In the above code, we have declared a String ' Hello ' with leading and trailing spaces.
Then we have used the 'strip( )' function to remove any unwanted spaces from beginning and end.
Unwanted spaces are stripped out of it.
Now, let us say you want the fill the right blocks with something other than spaces.
x = "***Hello**" y = x.strip('*') print(y)
In the above code, we have declared a String ' Hello ' with leading and trailing asterisk '*'.
Then we have used the 'strip( )' function to remove any asterisk '*' from beginning and end.
And asterisk '*' are stripped out of it.