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




lstrip( ) FUNCTION


lstrip( ) Function


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


Example :


x = "   Hello  "
y = x.lstrip()
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 'lstrip( )' function to remove the unwanted spaces from left side only.


y = x.rstrip( )

java_Collections

So, the unwanted spaces are stripped out from the left 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.lstrip('@*')
print(y)    


Output :



  Hello@ir

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


x = "*@Hello@ir"

java_Collections

So, we have used the 'lstrip( )' function to remove the unwanted characters i.e. '*, @' from the left side only.


y = x.lstrip('@*')

java_Collections

And '@' and '*' are stripped out only from the left side of the String.