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:
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Converting a List to String in Java
Python String ljust()
Python Program to Convert Celsius To Fahrenheit
Python zip()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python input()
JavaScript Eval: run a code string
Python List pop()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Transpose a Matrix
Format ZonedDateTime to String
Encode a String to UTF-8 in Java
Python Program to Reverse a Number
Python String isspace()
Python String format_map()
Python bool()
Python Program to Create a Long Multiline String
Python Program to Get the File Name From the File Path
Python String format()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python hash()
Python Inheritance
Python String join()
Python while Loop
Python Set add()
Python String islower()
String Hashing
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Set union()
Python Program to Find ASCII Value of Character
Python help()