Python String lstrip() Method

Example

Remove Leading Spaces from String:

txt = "     banana     "
x = txt.lstrip()
print("of all fruits", x, "is my favorite")

Run Instance

Definition and Usage

The lstrip() method removes all leading characters (whitespace is the default leading character to be removed).

Syntax

string.lstrip(characters)

Parameter Value

Parameter Description
characters Optional. A set of characters to be removed as leading characters.

More Examples

Example

Remove Leading Characters:

txt = ",,,,,ssaaww.....banana"
x = txt.lstrip(",.asw")
print(x)

Run Instance