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 Multiply Two Matrices
Python Global, Local and Nonlocal variables
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String isalpha()
Python setattr()
Python Anonymous / Lambda Function
Python String strip()
Python Program to Check the File Size
Python oct()
Converting String to Stream of chars
Python Program to Calculate the Area of a Triangle
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Illustrate Different Set Operations
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Slice Lists
Python Program to Merge Mails
JavaScript Methods of RegExp and String
Python Function Arguments
Python Program to Convert Two Lists Into a Dictionary
Python Program to Transpose a Matrix
Encode a String to UTF-8 in Java
Python bytes()
Python object()
Python String swapcase()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Exception Handling Using try, except and finally statement
Python divmod()
Python List
Python Program to Iterate Over Dictionaries Using for Loop
Python Program to Check If Two Strings are Anagram
Python type()
Python vars()