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 Statement, Indentation and Comments
Python String count()
Python Custom Exceptions
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Differentiate Between del, remove, and pop on a List
Python Dictionary fromkeys()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Program to Sort a Dictionary by Value
Python list()
Count Occurrences of a Char in a String
Python datetime
Python isinstance()
Python Anonymous / Lambda Function
Python Program to Randomly Select an Element From the List
Java InputStream to String
Python open()
Python Program to Display the multiplication Table
Python List index()
Python Set clear()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Compute all the Permutation of the String
Python List insert()
Python Program to Get the Full Path of the Current Working Directory
Python String isdecimal()
Python Program to Split a List Into Evenly Sized Chunks
Python String endswith()
Python help()
Python pass statement
Python staticmethod()
Python String strip()
Python Program to Get a Substring of a String
Deep Learning with Python - Francois Cholletf