String Methods
str.rstrip()
Remove consecutive characters from the trailing end until a character outside the allowed set is reached. With None or omitted chars, remove Python-defined whitespace. An explicit chars string supplies individual code points, not an exact prefix or suffix. Internal characters are retained. The original string is unchanged.
Formal Syntax & Structure
python syntaxpython
text.rstrip(chars=None, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| chars | str | None | Characters eligible for removal; None means whitespace. |
Return Value
str
Trimmed text.
Working Example
Example Snippetpython
print(repr("!!name!!".rstrip("!")))print(repr(" x ".rstrip()))