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 (spaces are the default leading characters to be removed).

Syntax

string.lstrip(characters)

Parameter Value

Parameter Description
characters Optional. A group 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