Python lstrip Function | trim string from left examples

Python lstrip() method is used to remove all leading White-space (characters) from the string. There is an option in “lstrip Function” to use or not a char type parameter. If the parameter is not provided, it removes all the leading spaces from the string.

Read more topic & links



chars (optional) : A list of chars to be removed.

Note: If the chars parameter is not provided, all leading whitespaces are removed from the string.

Return Value

Returns a copy of the string with leading (left) characters stripped.

lstrip() | Python trim string from left example

1. Removing left side white space from strings example

Output: EyeHunts

2. Remove special char- Python string lstrip

Output: EyeHunts

3. Remove substring from left

Will remove only first occurrence of substring from given string.

Output: The Python code

Runtime Error | lstrip()

Will throw an error, if you try to strip anything except a string. In the example trying to strip a Python List.

Output: AttributeError: type object ‘list’ has no attribute ‘lstrip’

Python lstrip Function trim string from left examples

Q: How to trim string from left in python?

Answer: Use lstrip() python function to remove(trim) left space from given string.

Do comment if you have any questions and doubts on this topic.

IDE: PyCharm 2020.1 (Community Edition)
macOS 10.15.4
Python 3.7
All Python Examples string.count python 3, so it may change its different from python 2 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.