str.rstrip
Remove characters at the end of the string.
Python 3.13
str.rstrip([chars])Parameters
- charsstr | Noneoptional
- The set of characters to remove; if not given, whitespace is removed.
Return value
A new string; the original is not changed.
Examples
Removing spaces on the right
Python 3.13
print('hello '.rstrip())hello
Removing trailing marks
Python 3.13
print('Hello!!!'.rstrip('!'))Hello
Details
chars is a set of individual characters, not a substring. To remove a specific suffix, use str.removesuffix.
