I want to know how does rstrip and lstrip works in python. Say, if I have a string
>> a = \'thisthat\'
>> a.rstrip(\'hat\')
out : \'this\'
>&g
lstrip
, rstrip
and strip
remove characters from the left, right and both ends of a string respectively. By default they remove whitespace characters (space, tabs, linebreaks, etc)
>>> a = ' string with spaces '
>>> a.strip()
'string with spaces'
>>> a.lstrip()
'string with spaces '
>>> a.rstrip()
' string with spaces'
You can use the chars parameter to change the characters it strips.
>>> a = '....string....'
>>> a.strip('.')
'string'
However, based on your question it sounds like you are actually looking for replace
>>> a = 'thisthat'
>>> a.replace('hat', '')
'thist'
>>> a.replace('this', '')
'that'