Home >>Python String Methods >Python String strip() Method

Python String strip() Method

Python String strip() Method

Python string strip() method is used to remove any leading spaces at the beginning and trailing spaces at the end or any characters. Space is the default leading character to remove.

Syntax:
string.strip(characters)

Parameter Values

Parameter Description
characters This is an optional parameter. It defines a set of characters to remove as leading or trailing characters.
Here is an example of Python strip() method:

txt = "     PHPTPOINT     "
x = txt.strip()
print("I work at", x, "as a Developer")

Output:
I work at PHPTPOINT as a Developer
Example 2:

txt = ",,,,,rrttgg.....Jerry..******..rrr"
x = txt.strip(",*.grt")
print(x)

Output:
Jerry

No Sidebar ads