The Python String strip() Method returns a copy of the string by stripping both the beginning and the string’s end.
The syntax of the method is: str.strip([chars]);
Key Points :
• This method removes only left and right characters, only if they match the argument given in strip() and return the copy of the string
• This method is used to erase whitespaces or some special character or any prefix or suffix from a certain string.
Python String strip(): Parameters
Given below is the parameter of strip() function:
• character: This is an optional parameter for indicating the characters to be removed from the string. This method will take all leading and trailing whitespaces out of the string if this parameter is not given. In other words, whitespace is the default value for this parameter.
Below is the python program to demonstrate the strip() function:
str = "####The Best Learning Resource for Online Education####"; print (str.strip( '#' ))
When we run above the program, the outcome is as follows:
The Best Learning Resource for Online Education
Below are several other functions that we can use to work with string in Python 3