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 String maketrans()
Python Program to Find the Largest Among Three Numbers
Python Operator Overloading
Python Program to Check Leap Year
Python Program to Capitalize the First Character of a String
Python Program to Convert Celsius To Fahrenheit
Python bool()
Convert char to String in Java
Python Program to Check Armstrong Number
Python delattr()
Python Program to Solve Quadratic Equation
Python Set isdisjoint()
APIs in Node.js vs Python - A Comparison
Java InputStream to String
Converting String to Stream of chars
Python Program to Sort Words in Alphabetic Order
Python String format_map()
Python del Statement
Python range()
Python Program to Find Factorial of Number Using Recursion
Python strptime()
Check If a String Is Numeric in Java
Python String startswith()
Count Occurrences of a Char in a String
Python String format()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Find Numbers Divisible by Another Number
JavaScript Methods of RegExp and String
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Check Whether a String is Palindrome or Not
Python Program to Differentiate Between del, remove, and pop on a List
How to Get Started With Python?