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:
Machine Learning with Python for everyone - Mark E.Fenner
Java InputStream to String
Python Program to Make a Simple Calculator
Python max()
Python Keywords and Identifiers
Python Program to Check Armstrong Number
Python frozenset()
Python frozenset()
Python Dictionary popitem()
APIs in Node.js vs Python - A Comparison
Python Program to Sort Words in Alphabetic Order
Python Program to Access Index of a List Using for Loop
Python chr()
Python Program to Transpose a Matrix
Reading an HTTP Response Body as a String in Java
Python Program to Merge Two Dictionaries
Python Program to Find ASCII Value of Character
Python String islower()
Python Program to Remove Duplicate Element From a List
Java Program to Permute All Letters of an Input String
Python String isidentifier()
Python bool()
Python datetime
Python id()
Python Set pop()
Python Input, Output and Import
Python Recursion
Python globals()
Python List extend()
Python String partition()
Python Program to Find Factorial of Number Using Recursion
Java String to InputStream