Join Regular Classroom : Visit ClassroomTech

Python String – strip() method

It is a method string in python that removes all the leading characters from the right and left side of the string. It uses space as a default leading value. Leading characters can be one or many.

Syntax:

string.strip(leading_characters)

Example 1:

s = ” CodeWindow
x = s.strip()
print(x)

Output:

CodeWindow

Explanation:

Here the leading character by default is space which has been removed from the right and left side of the original string.

Example 2:

s = “——-CodeWindow——–
x = s.strip(““)
print(x)

Output:

CodeWindow

Explanation:

Here the leading character is “” which has been removed from the left and right side of the original string.

Example 3:

s = “.,,,,codeWindowssoo,,–
x = s.strip(“,.-so“)
print(x)

Output:

codeWindow

Explanation:

Here the leading characters that needs to be removed are “,” “.” “” “s” “o”. These characters are removed from the right and left side of the string.

You Missed
Also Checkout