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.
Headings of Contents
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.
The syntax of Python string lstrip() method is:-
string lstrip function in Python support one argument that is chars.
chars – ( Optional ) A set of characters to remove as leading characters.
Python string lstrip method return new string.
Python string lstrip example
Here we will take some examples to understand lstrip function in Python.
a = ' PROGRAMMING' result = a.lstrip() print(result)
Output will be:- PROGRAMMING
a = '#####--&&Programming$$$' result = a.lstrip('#-&') print(result)
Output will be:- Programming$$$
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 endswith() method
- String casefold() method
- String center() method
- String capitalize() method
- String count() method
- String index() method
- String format() method
- String isalpha() method
- String isidentifier() method
- String islower() method
- String isupper() method
For More Information:- Click Here