I tried using rstrip()
and lstrip()
like so:
>>> a = 'thisthat'
>>> a.lstrip('this')
'at'
>>> a.rstrip('hat')
'this'
>>> a.rstrip('cat')
'thisth'
What exactly are these methods doing? I expected 'thist'
for the first case and 'that'
for the second case.
I'm not looking to fix the problem, I just want to understand the functionality.
See also How do I remove a substring from the end of a string? if you do want to fix a problem with removing something from the beginning or end of a string (or are trying to close such a duplicate question).