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:
Python Keywords and Identifiers
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Capitalize the First Character of a String
Python Program to Find Numbers Divisible by Another Number
Split a String in Java
Converting String to Stream of chars
Java InputStream to String
Python String rjust()
Python help()
Convert String to int or Integer in Java
Python Set difference_update()
Python bool()
Python Closures
Python Program to Convert Celsius To Fahrenheit
Python Program to Split a List Into Evenly Sized Chunks
Python List pop()
Python Set issuperset()
Python setattr()
Python Get Current time
Java String to InputStream
Python Program to Trim Whitespace From a String
Python time Module
Python super()
Python Program to Get File Creation and Modification Date
Deep Learning with Python - Francois Chollet
Python Program to Check If Two Strings are Anagram
Python classmethod()
Python map()
Python Dictionary popitem()
Python String format_map()
Python all()