rstrip( ) Function
The rstrip( ) Function is used to remove any unwanted character from the right side of the String with Space by default.
x = " Hello " y = x.rstrip() print(y,"World")
In the above code, we have declared a String ' Hello ' with leading and trailing spaces.
Then we have used the 'rstrip( )' function to remove the unwanted spaces from right side only.
So, the unwanted spaces are stripped out from the right side of the String.
Now, let us say you want the fill the right blocks with something other than spaces.
x = "**Hello@ir" y = x.rstrip('ri@') print(y)
In the above code, we have declared a String '**Hello@ir' with some unwanted characters (i.e. '@, i, r') on the right side.
So, we have used the 'rstrip( )' function to remove the unwanted characters i.e. '@, i, r' from the right side.
And '@, i, r' are stripped out from the right side of the String.