Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

str.lstrip

Removes a run of characters from the left edge while each belongs to the supplied set.

Version: Python 3.14; repository image, production runtime not attested

Syntax

s.lstrip(chars=None, /)

Removes a run of characters from the left edge while each belongs to the supplied set.

The argument is a collection of individual characters, not a whole prefix to match once.

Where chars is omitted or None, leading whitespace is removed. With "ab" every initial a or b is removed independently until X, leaving Xab. The second input contains only these characters and is stripped to the empty string.

assert "\u2003 x ".lstrip() == "x " and "abbaX".lstrip("ab") == "X"

Examples

print("ababaXab".lstrip("ab"))
print("aba".lstrip("ab") == "")

Result

Xab
True

Where chars is omitted or None, leading whitespace is removed. With "ab" every initial a or b is removed independently until X, leaving Xab. The second input contains only these characters and is stripped to the empty string.

Sources