How to remove all trailing whitespace of string in Python?


We can use the method rstrip() which returns a copy of the string in which all specified chars have been stripped from the end of the string. The default char to be trimmed is whitespace. For example:

>>> '   Hello   '.rstrip()
'   Hello'
>>> 'Ninja Turtles the movie     '.rstrip()
'Ninja Turtles the movie'
raja
Published on 12-Dec-2017 11:45:39
Advertisements