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
- If you want Remove Both side space form string- Python string strip() function
- Remove all over space in String- Python string replace function
Syntax
1 |
lstrip([chars]) |
Parameters
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
1 2 3 |
str1 = " EyeHunts " print(str1.lstrip()) |
Output: EyeHunts
2. Remove special char- Python string lstrip
1 2 3 4 5 |
# Given string string = "***## EyeHunts" # Removes given set of characters from left. print(string.lstrip("*#")) |
Output: EyeHunts
3. Remove substring from left
Will remove only first occurrence of substring from given string.
1 2 3 4 5 |
string = "The The Python code " # Argument doesn't contain leading 'g' # So, no characters are removed print(string.lstrip('The')) |
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.
1 2 3 |
list1 = [1, 2, 3] print(list.lstrip()) |
Output: AttributeError: type object ‘list’ has no attribute ‘lstrip’

Q: How to trim string from left in python?
Answer: Use lstrip() python function to remove(trim) left space from given string.
1 |
string.lstrip() |
Do comment if you have any questions and doubts on this topic.
Note:
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.