Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

strip function in python

  • In python, we are having another in-built function called "strip()".
  • The strip() function is used to remove the spaces of the starting and end of the string.
  • It is having one parameter character used to remove the begging or end character.
  • By default, it removes the white spaces at the beginning or end.
  • If there is no white space between the beginning or end, the string remains the same and returns the same string.
  • When the character we give does not match the start or end, it returns the same string.
  • If the character is given at start to remove then the space will be removed and the remaining will remain the same.
syntax: str. strip(char)

#write a python program to demonstrate the strip function()

  1. txt1="   my name is python"
  2. txt2="***my name is python***"
  3. txt3=",,,my name is python"
  4. txt1=txt1.strip()
  5. txt2=txt2.strip("*")
  6. txt3=txt3.strip(".")
  7. print(txt1)
  8. print(txt2)
  9. print(txt3)
Output: my name is python
               my name is python
               my name is python



This post first appeared on Java Tutorial - InstanceOfJava, please read the originial post: here

Share the post

strip function in python

×

Subscribe to Java Tutorial - Instanceofjava

Get updates delivered right to your inbox!

Thank you for your subscription

×