all Python 3Strings (str)function
str.rstrip
stripping
Return a copy with trailing characters removed (whitespace by default).
Syntax
s.rstrip([chars])
Same trap as lstrip, mirrored: the argument is a character set, so 'test.txt'.rstrip('.txt') returns 'tes'. Use str.removesuffix() (Python 3.9+) when you mean a suffix as a whole. Bare rstrip() is convenient for dropping the newline off a line read from a file, but it also eats meaningful trailing spaces if your data carries any.
Examples
print('hi '.rstrip()) # → hi
print('hixx'.rstrip('x')) # → hi
print('--a--'.rstrip('-')) # → --a
See also
Open in the full glossarydocs.python.orgReport an inaccuracy