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 Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Represent enum
Python filter()
Java String Conversions
Python String rpartition()
Convert String to Byte Array and Reverse in Java
Python issubclass()
Python Program to Randomly Select an Element From the List
Python Program to Iterate Through Two Lists in Parallel
Reading an HTTP Response Body as a String in Java
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python globals()
Python Program to Add Two Matrices
Python Modules
Python all()
Python Program to Print the Fibonacci sequence
Python Namespace and Scope
Python Sets
Python input()
Python Program to Access Index of a List Using for Loop
Machine Learning with Python for everyone - Mark E.Fenner
Python Numbers, Type Conversion and Mathematics
Python Keywords and Identifiers
Python Set add()
Python List count()
Python Multiple Inheritance
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Display Powers of 2 Using Anonymous Function
Java – String to Reader
Python Program to Shuffle Deck of Cards
Python Tuple index()
Python Program to Differentiate Between type() and isinstance()