Menu Close

Python String lstrip() Method

Python string lstrip

In this article, you will learn about the Python string lstrip() method along with some examples. lstrip function in Python is the best string function to remove leading characters from the string.

To understand this method you should have basic knowledge of Python string.

In the previous tutorial, we have been seen Python string lower() method to convert uppercase characters to lowercase characters.

Python string lstrip() method

Python lstrip() string method removes all the leading characters from a string. It takes a char type parameter which is optional. if the parameter is not provided then it removes all the spaces from the string.

Syntax

The syntax of Python string lstrip() method is:-

string.lstrip(chars)

Parameter

string lstrip function in Python support one argument that is chars.

chars – ( Optional ) A set of characters to remove as leading characters.

Return Type:

Python string lstrip method return new string.

Python string lstrip example

Here we will take some examples to understand lstrip function in Python.

Example 1:

a = '      PROGRAMMING'
result = a.lstrip()
print(result)

Output will be:- PROGRAMMING

Example 2:

a = '#####--&&Programming$$$'
result = a.lstrip('#-&')
print(result)

Output will be:- Programming$$$

Conclusion

In this python string method tutorial, you have learned the Python string lstrip method to remove all the leading characters from the left of the string.
If you want to remove all the spaces or any leading characters from the left of the string, Then you can go with lstrip function.

I hope this article will have helped you. if you like this article, please share it with your friends who want to learn Python programming from scratch to advanced.

String Methods


For More Information:- Click Here

Python String lower() Method
Python String replace() Method

Related Posts