Python 3 reference · String Methods
Python String lstrip() Method
Return a copy with leading characters removed: whitespace by default, or any of the characters you pass.
Python 3 Since 3.0
Syntax
str.lstrip(chars=None)
Parameters
| Parameter | Description |
|---|---|
chars optional |
A set of characters to remove (not a prefix!). Default: whitespace. |
Return value
A new string.
Examples
print(repr(" indented".lstrip()))
print("000123".lstrip("0"))
Output
'indented' 123
print("www.wikipedia.org".lstrip("w.")) # removes every leading w and . character!
print("www.wikipedia.org".removeprefix("www."))
Output
ikipedia.org wikipedia.org
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.rstrip()· Return a copy with trailing characters removed: whitespace by default, or any of the characters you pass.str.strip()· Return a copy with leading and trailing characters removed: whitespace by default, or any of the characters you pass.str.removeprefix()· Return the string without the given prefix if it starts with it; otherwise return it unchanged.- Python Strings · tutorial