String Methods
rstrip()
Remove whitespace or chosen characters from the right end.
str.rstrip(chars=None)
Remove whitespace or chosen characters from the right end.
Arguments
Parameters
| Name | Description |
|---|---|
| chars | Optional characters to remove from the right end; it is not a literal suffix. |
Result
Returns
A new string with matching trailing characters removed.
Run it
Try it
Run it and change it
text = "hello "
print("[" + text.rstrip() + "]") Output
Press Run to see what it prints.Worth knowing
rstrip(chars)removes any matching characters repeatedly, not one exact suffix. Useremovesuffix()for one exact suffix.