Join Regular Classroom : Visit ClassroomTech

Python String – lstrip() method

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

Syntax:

string.lstrip(leading_characters)

Example 1:

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

Output:

CodeWindow

Explanation:

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

Example 2:

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

Output:

CodeWindow——–

Explanation:

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

Example 3:

s = “…..,,,,sssooossssCodeWindow——–
x = s.lstrip(“,.-so“)
print(x)

Output:

CodeWindow——–

Explanation:

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

You Missed
Also Checkout