Skip to main content

lstrip()

The lstrip() method in Python is a string method that removes any leading characters (whitespace by default) from a string. It returns a new string with the leading characters removed.

Parameter Values

Parameter Description
chars

(optional) A string specifying the set of characters to be removed from the left side of the string. If not provided, whitespace characters are removed.

Return Values

The lstrip() method in Python returns a new str with leading characters removed.

How to Use lstrip() in Python

Example 1:

The lstrip() method removes any leading characters (whitespaces or specified characters) from a string.

print('   Hello, World!   '.lstrip())
Example 2:

You can also specify which characters to remove from the beginning of the string.

print('...Hello, World!...'.lstrip('.'))
Example 3:

If there are no leading characters to strip, the original string will be returned.

print('Hello, World!'.lstrip())