It's right in the docs:
lstrip(...)
S.lstrip([chars]) -> string or unicode
Return a copy of the string S with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping
'K'
is in 'KEY_'
, that's why your last example returns ''
.
Note that 'K'
would not have been removed if preceded by a character that is not in 'KEY_'
:
>>> 'KEY_xK'.lstrip('KEY_')
'xK'