Python3 strip() Method
Description
Python strip() method is used to remove specified characters (default is space) or character sequences from the beginning and end of a string.
Note:This method can only delete characters at the beginning or end, not characters in the middle part.
Syntax
Syntax of the strip() method:
str.strip([chars]);
Parameters
- chars -- The specified sequence of characters to remove from the beginning and end of the string.
Return Value
Returns a new string generated by removing the specified character sequence from the beginning and end of the string.
Example
The following example demonstrates how to use the strip() function:
Example (Python 3.0+)
The output of the above example is as follows:
this is **string** example....wow!!!
From the results, it can be noted that the characters in the middle part were not deleted.
The following example demonstrates that characters are deleted as long as the beginning and end contain characters from the specified character sequence:
Example (Python 3.0+)
The output of the above example is as follows:
3abcexample3
Other Extensions
Python3 Strings