strip() in-built function of Python is used to remove all the leading and trailing spaces from a string.
remove (optional): Character or a set of characters, that needs to be removed from the string.
The function can take one or no parameter. If no parameter is passed then only the leading and trailing spaces are removed.
Return Values :
The function returns another string with both leading and trailing characters being stripped off.
When the removed string matches perfectly then the modified string is returned with removed characters and spaces. When the remove string does not match then no modification is made to the original string.
The below code displays the working of strip() in various conditions.
Geeks for Geeks for Geeks for Geeks
Geeks for Geeks Geeksforgeeks
Practical Application :
The following code shows an application of strip() in python.
Length before strip() 17 Length after removing spaces 15
- Python string | strip()
- Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs())
- numpy string operations | strip() function
- Python | Pandas Series.str.strip(), lstrip() and rstrip()
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Merge Tuple String List values to String
- Python | Check if string ends with any string in given list
- Python | Sorting string using order defined by another string
- Python | Check if a given string is binary string or not
- String slicing in Python to rotate a string
- Python String | max()
- Python String
- Python | Add one string to another
- Python String | min()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.