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




strip( ) FUNCTION


strip( ) Function


The strip( ) Function is used to remove any unwanted character from the String with Space by default.


Example :


x = "   Hello  "
y = x.strip()
print(y)


Output :



  Hello

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


x = "  Hello "

java_Collections

Then we have used the 'strip( )' function to remove any unwanted spaces from beginning and end.


y = x.strip( )

java_Collections

Unwanted spaces are stripped out of it.


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


Example :


x = "***Hello**"
y = x.strip('*')
print(y)


Output :



  Hello

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


x = "***Hello**"

java_Collections

Then we have used the 'strip( )' function to remove any asterisk '*' from beginning and end.


y = x.strip('*')

java_Collections

And asterisk '*' are stripped out of it.