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 input()
Python frozenset()
Python Modules
Python Program to Create a Countdown Timer
Python String rsplit()
Python String istitle()
Python Set pop()
String Initialization in Java
Python Shallow Copy and Deep Copy
Python List append()
Adding a Newline Character to a String in Java
Python Program to Print the Fibonacci sequence
Python hasattr()
Python Set symmetric_difference_update()
Python Deep Learning Cookbook - Indra den Bakker
Java InputStream to String
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Transpose a Matrix
Python bytearray()
Python any()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python String count()
Python String endswith()
Python File I/O Operation
CharSequence vs. String in Java
Python __import__()
Python Program to Return Multiple Values From a Function
Python eval()
Python strptime()
Python Get Current time
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Dictionary values()