Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

I ran into what I believe is a bug, and I'm searching for affirmation or that I am not arrangement how this method functions. 

Here's my essential output:

(Pdb) x = 'KEY_K'

(Pdb) x.lstrip('K')

'EY_K'

(Pdb) x.lstrip('KE')

'Y_K'

(Pdb) x.lstrip('KEY')

'_K'

(Pdb) x.lstrip('KEY_')

''

(Pdb) import sys

(Pdb) sys.version

'2.7.11 (default, Dec  5 2015, 14:44:47) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)]

My understaning is that the last 'lstrip' in that model ought to have returned 'K', however it didn't. Does anybody know why?

1 Answer

0 votes
by (26.4k points)

From 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 is the reason your last model returns ''. 

Note that 'K' would not have been taken out whenever gone before by a character that isn't in 'KEY_':

>>> 'KEY_xK'.lstrip('KEY_')

'xK'

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 16, 2021 in Python by laddulakshana (12.7k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 27, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer

Browse Categories

...