Python String lstrip() method
The string. lstrip () method in Python returns a copy of the string with leading characters removed (based on the string argument passed).
Syntax
1 2 3 |
string.lstrip([chars]) |
Parameter
chars(optional): This parameter represents a string specifying the set of characters to be removed.
Return
This method returns a copy of the string with leading characters removed.
Example 1
1 2 3 4 5 6 7 8 9 10 11 12 |
# Python program explaining # the string.lstrip() method # initializing the String with whitespaces as the leading characteres string = " Hello World" print("Actual String:",string) # removing the leading the characters val = string.lstrip() # printing the striped value print("After lstrip() function") print("String:",val, ) |
Output
1 2 3 4 5 |
Actual String: Hello World After lstrip() function String: Hello World |
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Python program explaining # the string.lstrip() method # initializing the String string = ' Python programming is easy to learn' # the Leading whitepsace are removed from the string print(string.lstrip()) # no characters are removed as there is no whitepsace print(string.lstrip('programming')) print(string.lstrip('Py thon')) web = 'https://www.tutorialandexample.com' print(web.lstrip('htps://.')) |
Output
1 2 3 4 5 6 |
Python programming is easy to learn Python programming is easy to learn programming is easy to learn www.tutorialandexample.com |