
strip() method –
The strip() method removes that leading and trailing characters specified in argument from the string and returns a copy of it.
Syntax –
string.strip([chars])
chars (optional) – a set of characters to be removed from the string’s left and right part. By default if not argument passed then python removes all white spaces from both sides of the string.
Example –
In [1]: string1 = ' sirens of the sea '
In [2]: string1.strip()
Out[2]: 'sirens of the sea'
In [3]: string2 = '****python***********'
In [4]: string2.strip('*')
Out[4]: 'python'
Related Posts –
- Python String Method – Capitalize()
- Python String Method – title()
- Python String Method – center()
- Python String Method – count()
- Python String Method – startswith()
- Python String Method – endswith()
- Python String Method – find()
- Python String Method – index()
- Python String Method – isalnum()
- Python String Method – isalpha()
- Python String Method – isdecimal()
- Python String Method – isdigit()
- Python String Method – islower()
- Python String Method – istitle()
- Python String Method – isupper()
- Python String Method – join()
- Python String Method – lower()
- Python String Method – upper()
- Python String Method – swapcase()
- Python String Method – lstrip()
- Python String Method – rstrip()