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

ParameterDescription
chars optional A set of characters to remove (not a prefix!). Default: whitespace.

Return value

A new string.

Examples

Strip the left sideTry it yourself
print(repr("   indented".lstrip()))
print("000123".lstrip("0"))

Output

'indented'
123
chars is a set, not a prefixTry it yourself
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

VersionChange
Python 3.0Added