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:
Check if a String is a Palindrome in Java
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python all()
Python Set difference()
Python List append()
Python Operators
Python String rfind()
Python zip()
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Find LCM
Python Objects and Classes
Python Program to Parse a String to a Float or Int
Python String join()
Python sorted()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python List count()
Java – String to Reader
Python vars()
Python Deep Learning Cookbook - Indra den Bakker
Adding a Newline Character to a String in Java
Python String isdecimal()
Python bytes()
Python Set copy()
Python __import__()
Python Keywords and Identifiers
Python for Loop
Python String center()
Python bool()
String Set Queries
Python Program to Sort a Dictionary by Value
Python Shallow Copy and Deep Copy
Python float()