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 eval()
Python Set symmetric_difference_update()
Python object()
Python strptime()
Python Program to Convert Bytes to a String
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Transpose a Matrix
Python len()
Python Namespace and Scope
Python Program to Find the Size (Resolution) of a Image
Python Program to Find HCF or GCD
Python Sets
Java Program to Permute All Letters of an Input String
Deep Learning in Python - LazyProgrammer
Python String upper()
Python oct()
Python Program to Slice Lists
Python Get Current time
Python Program to Check If a List is Empty
Python exec()
Python format()
Split a String in Java
Python Program to Solve Quadratic Equation
Python @property decorator
Python String isidentifier()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Tuple index()
Python min()
How to get current date and time in Python?
Python String ljust()
Python Program to Illustrate Different Set Operations
Python String rfind()