Python String lstrip() Method

The lstrip() method is a string method that returns a copy of the string with leading characters removed. The leading characters are the ones at the beginning of the string. By default, it removes any whitespace characters, but you can also specify a set of characters to be removed as an argument.

Here are some examples of using the lstrip() method:

# example 1: remove leading whitespace characters
string = "   Hello World   "
print(string.lstrip())
# Hello World

# example 2: remove leading specific characters
string = ",,,,,ssaaww.....banana"
print(string.lstrip(",.asw"))
# banana

# example 3: remove leading specific characters in any order
string = "#$2Hello World#$2"
print(string.lstrip("$2#"))
# Hello World#$2

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Stock Market Predictions with LSTM in Python

Collections In Python

Python Count Occurrence Of Elements

Python One Liner Functions