Python String rstrip() Method
Example
Remove Trailing Spaces from String:
txt = " banana " x = txt.rstrip() print("of all fruits", x, "is my favorite")
Definition and Usage
The rstrip() method removes all trailing characters (characters at the end of the string), spaces are the default trailing characters to be removed.
Syntax
string.rstrip(characters)
Parameter Value
Parameter | Description |
---|---|
characters | Optional. A set of characters to be removed as trailing characters. |
More Examples
Example
Remove Trailing Characters:
txt = "banana,,,,,ssaaww....." x = txt.rstrip(",.asw") print(x)