Python String | rstrip method
Start your free 7-days trial now!
str.rstrip(~) method returns a string with the specified trailing characters removed. Default is to remove all trailing spaces (i.e. spaces on the right).
The string specifying the combination of trailing characters to remove from right of the string. Default is whitespace.
A string with the specified trailing characters stripped.
To strip all trailing whitespace from
x = "Dog "x.rstrip()'Dog'
To remove all combinations of trailing
' re' from
y = "SkyTowner "y.rstrip(' re')'SkyTown'
We remove all combinations of
'e' from the end of the string which gives us return value of
To remove all trailing
'R' from "SkyTowner":
z = "SkyTowner"z.rstrip('R')'SkyTowner'
Note that no trailing characters are removed as there is a mismatch at the very right of the string where
char argument of
'R' does not match with
'r'. As this shows,
rstrip(~) method is case sensitive.