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:
Java – Generate Random String
Python List extend()
Python Program to Append to a File
Intelligent Projects Using Python - Santanu Pattanayak
Python del Statement
Python input()
Python String split()
Python classmethod()
Array to String Conversions
Python Exception Handling Using try, except and finally statement
Python Set symmetric_difference_update()
Python Program to Check the File Size
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python String format()
Python staticmethod()
Python Program to Print the Fibonacci sequence
Python Program to Check If a String Is a Number (Float)
Map to String Conversion in Java
Case-Insensitive String Matching in Java
Python Program to Count the Occurrence of an Item in a List
Count Occurrences of a Char in a String
Python String join()
Format ZonedDateTime to String
Convert String to Byte Array and Reverse in Java
Python Recursion
Python RegEx
Python Dictionary setdefault()
Python Decorators
Python Set difference()
Python type()
Python Matrices and NumPy Arrays
Python String isupper()