THE WORLD'S LARGEST WEB DEVELOPER SITE

Python String rstrip() Method

❮ String Methods


Example

Remove spaces to the right of the string:

txt = "     banana     "

x = txt.rstrip()

print("of all fruits", x, "is my favorite")
Run example »

Definition and Usage

The rstrip() method removes any trailing characters (characters at the end a string), space is the default trailing character to remove.


Syntax

string.rstrip(characters)

Parameter Values

Parameter Description
characters Optional. A set of characters to remove as trailing characters

More Examples

Example

Remove the trailing characters:

txt = "banana,,,,,ssaaww....."

x = txt.rstrip(",.asw")

print(x)
Run example »

❮ String Methods