Lstrip() method of str class

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:

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:

Watson

a

aioua

 


Copyright 2024 © pythontic.com