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 Program Read a File Line by Line Into a List
Python Program to Remove Punctuations From a String
Python Dictionary pop()
Python String isidentifier()
Python locals()
Python Program to Get the Full Path of the Current Working Directory
Python List reverse()
Python delattr()
Python Program to Capitalize the First Character of a String
Python Program to Safely Create a Nested Directory
Python Set add()
Python Program to Remove Duplicate Element From a List
Python Program to Find Numbers Divisible by Another Number
Python Shallow Copy and Deep Copy
Convert String to int or Integer in Java
Python Program to Extract Extension From the File Name
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Print all Prime Numbers in an Interval
Deep Learning in Python - LazyProgrammer
Python if...else Statement
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python dir()
Python Package
Python break and continue
Python int()
Python object()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
CharSequence vs. String in Java
Python isinstance()
Python open()
Python Modules
Python map()