
rstrip() method –
The rstrip() method removes all trailing characters specified in the argument from the right and returns a copy of the string.
syntax –
string.rstrip([chars])
chars ( optional ) – Characters to remove from the end of a string. By default if no characters are specified then Python removes all trailing white space from the end of a string.
Example –
In [1]: string1 = ' Python '
In [2]: string1.rstrip()
Out[2]: ' Python'
In [3]: string2 = '****python****'
In [4]: string2.rstrip('*')
Out[4]: '****python'
In [5]: string3 = 'python3'
In [6]: string3.rstrip('3')
Out[6]: 'python'
Related Posts –
- Python String Method – Capitalize()
- Python String Method – title()
- Python String Method – center()
- Python String Method – count()
- Python String Method – startswith()
- Python String Method – endswith()
- Python String Method – find()
- Python String Method – index()
- Python String Method – isalnum()
- Python String Method – isalpha()
- Python String Method – isdecimal()
- Python String Method – isdigit()
- Python String Method – islower()
- Python String Method – istitle()
- Python String Method – isupper()
- Python String Method – join()
- Python String Method – lower()
- Python String Method – upper()
- Python String Method – swapcase()
- Python String Method – lstrip()