Table of Contents
The lstrip() method returns a copy of the string with leading characters removed (based on the string argument passed).
The lstrip() removes characters from the left based on the argument (a string specifying the set of characters to be removed).
The syntax of lstrip() is:
string.lstrip([chars])
1. lstrip() Parameters
- chars (optional) – a string specifying the set of characters to be removed.
If chars argument is not provided, all leading whitespaces are removed from the string.
2. Return Value from lstrip()
lstrip() returns a copy of the string with leading characters stripped.
All combinations of characters in the chars argument are removed from the left of the string until the first mismatch.
3. Example: Working of lstrip()
random_string = ' this is good '
# Leading whitepsace are removed
print(random_string.lstrip())
# Argument doesn't contain space
# No characters are removed.
print(random_string.lstrip('sti'))
print(random_string.lstrip('s ti'))
website = 'https://www.maixuanviet.com'
print(website.lstrip('htps:/.'))
Output
this is good this is good his is good www.maixuanviet.com
Related posts:
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Program to Check if a Key is Already Present in a Dictionary
Python Numbers, Type Conversion and Mathematics
Python List
Python float()
Java String Conversions
Python String casefold()
Python any()
Python Set symmetric_difference_update()
Python String rfind()
Python Operator Overloading
Python Program to Count the Number of Occurrence of a Character in String
Python timestamp to datetime and vice-versa
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Keywords and Identifiers
Python Program to Count the Number of Digits Present In a Number
Python Dictionary update()
Python Program to Remove Punctuations From a String
Python Set update()
Python int()
Python Machine Learning - Sebastian Raschka
Python Program to Find the Sum of Natural Numbers
Python print()
Python Global Keyword
Python List remove()
Python Program to Solve Quadratic Equation
Python id()
Python Program to Check if a Number is Positive, Negative or 0
Converting a Stack Trace to a String in Java
Python break and continue
Python Set add()
Python Program to Multiply Two Matrices