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:
Convert Character Array to String in Java
Python Set pop()
Python Operators
Python strptime()
Jackson – Marshall String to JsonNode
Python Program to Find Factorial of Number Using Recursion
Python Program to Check Armstrong Number
Python Program to Find HCF or GCD
Converting String to Stream of chars
Node.js vs Python for Backend Development
Python float()
Python hasattr()
Python Program to Find Sum of Natural Numbers Using Recursion
Python abs()
Python Program to Check If a String Is a Number (Float)
Python Program to Find Hash of File
Python String isspace()
Python frozenset()
Python Program to Compute the Power of a Number
Python pass statement
Python Strings
Python Program to Sort Words in Alphabetic Order
Python Program to Find Armstrong Number in an Interval
Python String upper()
Python String partition()
Python Program to Convert Kilometers to Miles
Python Set update()
Python Program to Return Multiple Values From a Function
Python Program to Print Hello world!
Python slice()
Python Program to Print the Fibonacci sequence
JavaScript Methods of RegExp and String