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 to Check Armstrong Number
Python Program to Transpose a Matrix
Convert char to String in Java
Python Program to Copy a File
Python Set issubset()
Python print()
Python Set clear()
Python Program to Check If a List is Empty
Python hash()
Python globals()
Python Program to Convert Decimal to Binary Using Recursion
Python String rjust()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python memoryview()
Python String join()
Split a String in Java
Python String rsplit()
Python String partition()
Machine Learning with Python for everyone - Mark E.Fenner
Python Set copy()
Python set()
Python Program to Remove Punctuations From a String
Python bool()
Case-Insensitive String Matching in Java
Python Operators
Python Program to Get the Last Element of the List
Python Program to Add Two Matrices
Python Program to Create a Countdown Timer
Python Objects and Classes
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python String casefold()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel