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 Type Conversion and Type Casting
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Find the Factors of a Number
Python Program to Find Numbers Divisible by Another Number
Python Program to Make a Simple Calculator
Python print()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Tuple index()
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Differentiate Between type() and isinstance()
Python String maketrans()
Intelligent Projects Using Python - Santanu Pattanayak
Python abs()
Python *args and **kwargs
Python Program to Count the Number of Digits Present In a Number
Python String encode()
Python Dictionary values()
Python String casefold()
Python Dictionary keys()
Python Program to Print Output Without a Newline
Python List
Python Program to Append to a File
Python List remove()
Python exec()
Python List pop()
Python String islower()
Python Closures
Java String to InputStream
Python Program to Illustrate Different Set Operations
Format ZonedDateTime to String
Python Artificial Intelligence Project for Beginners - Joshua Eckroth