Python Function Reference

str.lstrip

Remove characters at the beginning of the string.

Python 3.13
str.lstrip([chars])

Parameters

charsstr | Noneoptional
The set of characters to remove; if not given, whitespace is removed.

Return value

A new string; the original is not changed.

Examples

Removing spaces on the left

Python 3.13
print('  hello'.lstrip())
hello

Removing leading zeros

Python 3.13
print('000123'.lstrip('0'))
123

Details

chars is a set of individual characters, not a substring. To remove a specific prefix, use str.removeprefix.

See also

Where to learn