- 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()
- txt1=" my name is python"
- txt2="***my name is python***"
- txt3=",,,my name is python"
- txt1=txt1.strip()
- txt2=txt2.strip("*")
- txt3=txt3.strip(".")
- print(txt1)
- print(txt2)
- print(txt3)
Output: my name is python
my name is python
my name is python