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:
String Initialization in Java
Python Matrices and NumPy Arrays
Python Program to Count the Number of Digits Present In a Number
Python Program to Remove Duplicate Element From a List
Python Program to Copy a File
Python String replace()
Python Set union()
Python Program to Get File Creation and Modification Date
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Parse a String to a Float or Int
Python Objects and Classes
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python datetime
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Program to Trim Whitespace From a String
Python Program to Generate a Random Number
Python Program to Check Prime Number
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Compute all the Permutation of the String
Python String format_map()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Functions
Python del Statement
Python Program to Get a Substring of a String
Python String isdigit()
Python list()
Python List insert()
Python Program to Print Hello world!
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program Read a File Line by Line Into a List
Python Program to Print the Fibonacci sequence