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 bytes()
Python Program to Extract Extension From the File Name
Java – Generate Random String
Python tuple()
Why String is Immutable in Java?
Python dict()
Python while Loop
Python String rsplit()
Python Type Conversion and Type Casting
Python Program to Sort a Dictionary by Value
Python String title()
Python Program to Check If a List is Empty
Python bytearray()
Python Global, Local and Nonlocal variables
Python Dictionary items()
Python Custom Exceptions
Python Program to Reverse a Number
Python File I/O Operation
Python Dictionary keys()
Python Program to Check if a Key is Already Present in a Dictionary
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Namespace and Scope
Python Objects and Classes
Python String maketrans()
Python String rstrip()
Python Program to Iterate Over Dictionaries Using for Loop
Python Matrices and NumPy Arrays
Python exec()
Python Object Oriented Programming
Python Exception Handling Using try, except and finally statement
Python Tuple
String Processing with Apache Commons Lang 3