The rstrip() method in Python String returns a copy of the string where all the chars have been stripped beginning from the end of the string with whitespace characters as the default. The rstrip() method in Python string thus returns a copy of the string that comprises trailing characters removed (depending on the string argument that passed). If in case there is no argument passed, then it may remove the trailing spaces.
Following is the syntax for rstrip() method:
This method is supposed to return a copy of the string in which every chars have been stripped from the end of the string with whitespace characters being the default one.
The example below shows the usage of the rstrip() method.
#!/usr/bin/python str = " this is string example....wow!!! "; print str.rstrip() str = "88888888this is string example....wow!!!8888888"; print str.rstrip('8')
When the above program is run, it may produces the following result:
this is string example....wow!!! 88888888this is string example....wow!!!
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.