Tutorial Study Image

Python lstrip()

The lstrip() function in python removes the leading characters in the copy of the original string based on the arguments given. The method returns this copy as output.


string.lstrip([chars]) #where chars are those to remove as leading characters
 

lstrip() Parameters:

The lstrip() function takes characters as its parameter. If chars are not provided the leading space is removed from the string.

Parameter Description Required / Optional
chars characters to remove as leading characters Optional

lstrip() Return Value

The return value is always a string. Until the first match found, all combinations of characters are removed from the left onwards.

Input Return Value
string copy of string

Examples of lstrip() method in Python

Example 1: How lstrip() works in Python?


# Variable declaration  
string1 =  "  Python  "  
# Leading whitepsace are removed
print(string1.lstrip()) 
string2 =  ",,,,,ssaaww.....programming" 
print(string2.lstrip(",.asw"))  
 

Output:


 Python  
programming 

Example 2: Woking of Istrip


# Variable declaration  
string1 =  "$$$$-Python-$$$$"  
# Calling function  
string2 = string1.lstrip('$')  
# Displaying result  
print(string1)  
print(string2)  
 

Output:


$$$$-Python-$$$$
-Python-$$$$