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 String center()
Python Tuple count()
Python Objects and Classes
Python Program to Measure the Elapsed Time in Python
Python Program to Print Hello world!
Python Program to Safely Create a Nested Directory
Python Program to Remove Duplicate Element From a List
Python Set add()
Java InputStream to String
Python Dictionary fromkeys()
Python break and continue
Python Program to Swap Two Variables
Python Program to Differentiate Between type() and isinstance()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String maketrans()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Randomly Select an Element From the List
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python String strip()
Python Program to Copy a File
Python hasattr()
Python ord()
Python locals()
Python String count()
Python Program to Concatenate Two Lists
Python Errors and Built-in Exceptions
Python getattr()
Converting a Stack Trace to a String in Java
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Convert Kilometers to Miles
Python String rpartition()