Python String lstrip() Method Tutorial

In this section, we will learn what String lstrip() method is and how to use it in Python.

What is String lstrip() Method in Python?

The Python string lstrip() method is used to strip the white spaces from the leading part (beginning) of a string value.

This means if the target string value has white spaces at its beginning, then calling this method will clear out those spaces.

Note that by default, this method will remove the leading white spaces, but it also can take an optional argument that accepts a different type of character to be removed from the leading of a string value.

For example, if the beginning contains 0s and we want to remove them, then we can put the value 0 as the argument of this method and so this time the method will remove the leading 0s from the string.

Python String lstrip() Method Syntax:

string.lstrip(character)

String lstrip() Method Parameter

The method takes one optional argument and that is the character (or a set of characters) we want to remove from the beginning part of a string value. The default value is set to white space.

String lstrip() Method Return Value

The return value of this method is a new string with its beginning part is removed from white space (or removed from the value specified as the argument of the method).

Note: the method does not change the original content but instead will create a new one and return that as a result.

Example: using python string lstrip() method

s1 = "*************My name is John Doe"

print(s1.lstrip("*"))

Output:

My name is John Doe
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies