Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




rstrip( ) FUNCTION


rstrip( ) Function


The rstrip( ) Function is used to remove any unwanted character from the right side of the String with Space by default.


Example :


x = "   Hello  "
y = x.rstrip()
print(y,"World")


Output :



   Hello World

In the above code, we have declared a String '  Hello ' with leading and trailing spaces.


x = "  Hello "

java_Collections

Then we have used the 'rstrip( )' function to remove the unwanted spaces from right side only.


y = x.rstrip( )

java_Collections

So, the unwanted spaces are stripped out from the right side of the String.


Now, let us say you want the fill the right blocks with something other than spaces.


Example :


x = "**Hello@ir"
y = x.rstrip('ri@')
print(y)


Output :



  ***Hello

In the above code, we have declared a String '**Hello@ir' with some unwanted characters (i.e. '@, i, r') on the right side.


x = "**Hello@ir"

java_Collections

So, we have used the 'rstrip( )' function to remove the unwanted characters i.e. '@, i, r' from the right side.


y = x.rstrip('ri@')

java_Collections

And '@, i, r' are stripped out from the right side of the String.