How to remove all trailing whitespace of string in Python?

PythonServer Side ProgrammingProgramming

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'
Updated on 30-Sep-2019 06:41:51