lstrip() method of str class

The lstrip method of str class removes leading characters of a string as specified in chars parameter of the method.

Str Updated 13 Mar 2017 1 min read

Method Name

lstrip

Method Signature

lstrip([chars])

Method Overview

  • The lstrip() method removes leading characters in a string as specified in the chars parameter and returns a new string object.
  • All the characters in the specified in the char parameter are matched against the first character of the string. If any of the characters specified in char found as the first character it is removed. This process continues till the first character of the string is not a character specified in chars parameter
  • If chars parameter is not provided, leading whitespaces will be removed

Example

python
rawString    = "Mr.Watson"

newString    = rawString.lstrip('.rM')

print(newString)

rawString    = ".eioua"

newString    = rawString.lstrip('ouie.')

print(newString)

rawString    = ".aioua"

newString    = rawString.lstrip('ouie.')

print(newString)

Output

Output
Watson

a

aioua