YouTip LogoYouTip

Python3 String Strip

# Python3.x Python3 strip() Method [![Image 3: Python3 Strings](#) Python3 Strings](#) * * * ## Description The Python strip() method is used to remove specified characters (default is whitespace) or character sequences from the beginning and end of a string. **Note:** This method can only remove characters from the beginning or the end, not from the middle of the string. ## Syntax The syntax for the strip() method is: str.strip(); ## Parameters * chars -- The character sequence to be removed from the beginning and end of the string. ## Return Value Returns a new string with the specified character sequence removed from the beginning and end. ## Example The following examples demonstrate the usage of the strip() function: ## Example (Python 3.0+) #!/usr/bin/python3 str = " *****this is **string** example....wow!!!***** "print(str.strip('*'))# Specify the string * The output of the above example is: this is **string** example....wow!!! As can be seen from the result, the characters in the middle part were not deleted. The following example demonstrates that characters are deleted as long as they are present in the specified character sequence at the beginning or end: ## Example (Python 3.0+) #!/usr/bin/python3 str = "123abctutorial321"print(str.strip('12'))# Character sequence is 12 The output of the above example is: 3abctutorial3 * * Python3 Strings](#)
← Python3 String TitlePython3 String Strip β†’