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 Global, Local and Nonlocal variables
Python Inheritance
Python zip()
Map to String Conversion in Java
Python Program to Differentiate Between type() and isinstance()
Python super()
Python Program to Shuffle Deck of Cards
Python Program to Count the Occurrence of an Item in a List
Python Dictionary update()
Python str()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
How to get current date and time in Python?
Python Set issuperset()
Python Tuple index()
Python Program to Convert String to Datetime
Python Program to Check Whether a String is Palindrome or Not
Python Dictionary pop()
Python File I/O Operation
Python String isnumeric()
Python sorted()
Intelligent Projects Using Python - Santanu Pattanayak
Python abs()
Python Function Arguments
Python String rstrip()
Python Program to Remove Duplicate Element From a List
Check if a String is a Palindrome in Java
String Processing with Apache Commons Lang 3
Python List clear()
Python Numbers, Type Conversion and Mathematics
Python round()
Python String strip()
Python Program to Find Hash of File