Python provides different methods in order to work with string types or objects. One of the string methods is the
rstrip() method that is used to right strip. The rstrip() method removes all white spaces or specified characters on the left side of the string.
rstrip() Method Syntax
The syntax of the rstrip() method is like below.
- STRING is the string value or variable where the strip operation occurs.
- CHAR is the character which will be stripped. CHAR is optional where if not specified the white spaces are stripped from left.
Strip Right Spaces From String
The strip method can be used to strip white spaces from the right. We do not provide any parameter to the strip() method.
name=" ismail " stripped_name = name.rstrip()
Strip Right Characters From String
The rstrip() method can be used to strip specified characters from the right of the string. We can specify single or more characters. In the following example, we remove the “abc” characters from the right part of the string.
name="abcismailabc" stripped_name = name.strip("abc")