Python String lstrip()

The lstrip() removes characters from the left based on the argument (a string specifying the set of characters to be removed).

The syntax of lstrip() is:

 string.lstrip([chars])

lstrip() Parameters

  • chars (optional) - a string specifying the set of characters to be removed.

If chars argument is not provided, all leading whitespaces are removed from the string.


Return Value from lstrip() 

lstrip() returns a copy of the string with leading characters stripped.

All combinations of characters in the chars argument are removed from the left of the string until the first mismatch.


Example: Working of lstrip()

 random_string = ' this is good ' # Leading whitepsace are removed print(random_string.lstrip()) # Argument doesn't contain space # No characters are removed. print(random_string.lstrip('sti')) print(random_string.lstrip('s ti')) website = 'https://www.programiz.com/' print(website.lstrip('htps:/.'))

Output

 this is good this is good his is good www.programiz.com/

Also Read:

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges