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 delattr()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Add Two Matrices
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Dictionary get()
Python String encode()
Python String lower()
Python Closures
Python Program to Display Powers of 2 Using Anonymous Function
Python float()
Python chr()
Python List sort()
Python String swapcase()
Python sum()
Python time Module
How to Get Started With Python?
Python String zfill()
Python Data Types
Python String maketrans()
Python Dictionary items()
Python Program to Check Whether a String is Palindrome or Not
Python complex()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Convert String to Byte Array and Reverse in Java
Python Program to Count the Occurrence of an Item in a List
Python Program to Get a Substring of a String
Python Program to Check if a Number is Odd or Even
Python String ljust()
Python String upper()
Check If a String Is Numeric in Java
Why String is Immutable in Java?
Machine Learning with Python for everyone - Mark E.Fenner