Skip to content
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

NameDescription
charsOptional 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. Use removesuffix() for one exact suffix.

Related entries