The lstrip() function doesn't behave in exactly the way you think it might. x.lstrip(argument) removes any of the characters in argument from the left of the string x until it reaches a character not in argument.

So 'KEY_K'.lstrip('KEY_') generates '' because the last character, K, is in KEY_.

Answer from gtlambert on Stack Overflow
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › lstrip.html
lstrip — Python Reference (The Right Way) 0.1 documentation
lstrip · Edit on GitHub · Returns a copy of the string with leading characters removed. str. lstrip([chars]) chars · Optional. String specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix; ...
🌐
W3Schools
w3schools.com › python › ref_string_lstrip.asp
Python String lstrip() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The lstrip() method removes any leading characters ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-lstrip-method
Python String lstrip() Method - GeeksforGeeks
November 12, 2024 - The lstrip() method removes leading whitespace characters from a string. We can also specify custom characters to remove from the beginning/starting of the string. Let's take an example to remove whitespace from the starting of a string.
🌐
Codecademy
codecademy.com › docs › python › strings › .lstrip()
Python | Strings | .lstrip() | Codecademy
October 11, 2023 - Learn the basics of Python 3.13, one of the most powerful, versatile, and in-demand programming languages today. ... The .lstrip() method removes the whitespace at the beginning of a string.
🌐
Programiz
programiz.com › python-programming › methods › string › lstrip
Python String lstrip()
The lstrip() method returns a copy of the string with leading characters removed (based on the string argument passed).
🌐
Tutorialspoint
tutorialspoint.com › python › string_lstrip.htm
Python String lstrip() Method
The Python String lstrip() method, as the name suggests, strips all the specified characters in a string from the beginning. That means, the method removes all combinations of the specified characters leading the string until a different character
🌐
Mimo
mimo.org › glossary › python › string-strip
Mimo: The coding platform you need to learn Web Development, Python, and more.
Python provides three related methods: strip() – removes from both ends · lstrip() – removes from the left · rstrip() – removes from the right · Python · Open in MimoOpen in MimoCopy Code · url = " www.example.com " print(url.lstrip()) # Removes only from the start print(url.rstrip()) ...
Find elsewhere
🌐
Python Tutorial
pythontutorial.net › home › python string methods › python string lstrip()
Python String lstrip(): Removing Leading Characters
December 28, 2020 - Use the Python string lstrip(chars) method to return a copy of a string with the leading characters removed.
🌐
Vultr Docs
docs.vultr.com › python › standard library › str › lstrip()
Python str lstrip() - Remove Leading Spaces
December 26, 2024 - The str.lstrip() method in Python is a straightforward and useful string manipulation tool designed to remove leading whitespace characters from the beginning of a string. Whether the unwanted space is a space character, tab, newline, or another ...
🌐
Scaler
scaler.com › home › topics › python lstrip() function
Python lstrip() Function - Scaler Topics
December 19, 2022 - The lstrip function stops removing leading characters from the left of the string when the character string specified there does not match the string that is to be stripped. Explore Scaler Topics Python Tutorial and enhance your Python skills with Reading Tracks and Challenges.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-methods-set-3-strip-lstrip-rstrip-min-max-maketrans-translate-replace-expandtabs
Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs()) - GeeksforGeeks
2. lstrip():- This method is used to delete all the leading characters mentioned in its argument. 3. rstrip():- This method is used to delete all the trailing characters mentioned in its argument.
Published: July 23, 2025
🌐
Hyperskill
hyperskill.org › university › python › strip-in-python
Python strip(), lstrip(), rstrip(): Remove Whitespace & Characters
June 5, 2026 - How do I remove whitespace from a string in Python? Use strip() to remove from both ends: ' hello '.strip() → 'hello'. Use lstrip() for left only, rstrip() for right only.
🌐
Jobtensor
jobtensor.com › Tutorial › Python › en › String-Methods-lstrip
Python String lstrip(), Definition, Syntax, Parameters, Examples | jobtensor
.PY Python SciPy · capitalize() ... splitlines() startswith() strip() swapcase() title() translate() upper() zfill() The lstrip() method removes any leading characters (space is the default leading character to remove) string.lstrip(chars) testStr = " Python " result = ...
🌐
ItsMyCode
itsmycode.com › python-string-lstrip
Python String lstrip() - ItsMyCode
October 19, 2024 - If we do not pass any arguments to lstrip() function, by default, all leading whitespaces are truncated from a string. If the string does not have any whitespaces at the beginning, the string will be returned as-is, matching the original string. If the characters passed in the arguments do not match the characters at the beginning of the string, it will stop removing the leading characters. # Only leading whitespaces are removed text1 = ' Python Programming ' print(text1.lstrip()) # Remove the whitespace and specified character at # leading end text2 = ' code its my code ' print(text2.lstrip(' code')) # Remove the specified character at # leading end text3 = 'code its my code' print(text3.lstrip('code'))
🌐
Real Python
realpython.com › python-strip
How to Strip Characters From a Python String – Real Python
October 22, 2025 - If you need to remove characters from only one side of a string, then use .lstrip() for the beginning or .rstrip() for the end. Just like .strip(), they remove individual occurrences of a set of specified characters rather than full substrings, and stop as soon as they encounter a character that’s not in the given set.
🌐
David Bieber
davidbieber.com › snippets › 2020-12-26-pythons-strip-lstrip-and-rstrip-in-javascript
Python's strip, lstrip, and rstrip in JavaScript | David Bieber
Python provides some convenient functions for manipulating strings: strip, lstrip, and rstrip. Recently I was writing some JavaScript and wanted to use rstrip. So, I’ve implemented all three. Here they are: The Python strip method in JavaScript In Python, strip removes whitespace from the ...
🌐
Learn By Example
learnbyexample.org › python-string-lstrip-method
Python String lstrip() Method - Learn By Example
April 20, 2020 - Python · Strips characters from the left end of a string · The lstrip() method removes whitespace from the beginning (leading) of the string by default. By adding chars parameter, you can also specify the characters you want to strip. ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.lstrip.html
pandas.Series.str.lstrip — pandas 3.0.5 documentation
Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from left side. Replaces any non-strings in Series with NaNs. Equivalent to str.lstrip().
🌐
Tutorialspoint
tutorialspoint.com › python › lstrip_method.htm
lstrip() Method
Following is the syntax for lstrip() method − This method returns a copy of the string in which all chars have been stripped from the beginning of the string (default whitespace characters).