Python string Method - lstrip()

www.‮i‬giftidea.com

The lstrip() method is a built-in string method in Python that returns a new string with leading whitespace characters removed from the left side of the string.

Syntax:

string.lstrip([characters])

Here, string is the string from which the characters should be stripped. The optional characters parameter specifies the characters to be removed from the left side of the string. If no argument is passed to the lstrip() method, it will remove all leading whitespace characters (spaces, tabs, newlines, etc.).

Example:

text = "   Hello World   "
print(text.lstrip())   # removes all leading whitespaces
print(text.lstrip(' H')) # removes all leading spaces and 'H' from the string

Output:

'Hello World   '
'e World   '