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.
Parameters
| Name | Description |
|---|---|
| chars | Optional characters to remove from the right end; it is not a literal suffix. |
Returns
A new string with matching trailing characters removed.
Try it
Run it and change it
text = "hello "
print("[" + text.rstrip() + "]")
Worth knowing
rstrip(chars)removes any matching characters repeatedly, not one exact suffix. Useremovesuffix()for one exact suffix.