rstrip() method of str class

rstrip() method of python str class returns new string object with specified leading characters removed. If no characters specified strips white spaces.

Str Updated 14 Mar 2017 1 min read

Method Name

rstrip

Method Signature

rstrip([chars])

Method Overview

  • The rstrip() method removes trailing characters in a string as specified in the chars parameter and returns a new string object.
  • All the characters specified in the chars parameter are matched against the last character of the string.
  • If any of the characters specified in chars found as the last character it is removed.
  • This process continues till the last character of the string is not a character specified in chars parameter
  • If chars parameter is not provided, trailing white spaces will be removed

Output

Output
functionCall = "SortFunction()"

functionName = functionCall.rstrip("()")

print("Original string:{}".format(functionCall))

print("String obtained after removing trailing chars:{}".format(functionName))

Example

python
Original string:SortFunction()

String obtained after removing trailing chars:SortFunction