Python String lstrip() method
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
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
# 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
Actual String: Hello World After lstrip() function String: Hello World
Example 2
# 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
Python programming is easy to learn Python programming is easy to learn programming is easy to learn www.tutorialandexample.com
