Calling the help
function shows the following:
Help on built-in function lstrip:
lstrip(chars=None, /) method of builtins.str instance
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
Which, clearly means that any white-space in the starting (i.e. left) will be chopped-off or if the chars
argument is specified it will remove those characters if and only if the string begins with any of the specified characters i.e. if you pass 'abc'
as an argument then the string should start with any of 'a'
,'b'
or 'c'
else the function won't change anything.
The string need not begin with the 'abc'
as a whole.
print(' the left strip'.lstrip()) # strips off the whitespace
the left strip
>>> print('ththe left strip'.lstrip('th')) # strips off the given characters as the string starts with those
e left strip
>>> print('ththe left strip'.lstrip('left')) # removes 't' as 'left' contatins 't' in it
hthe left strip
>>> print('ththe left strip'.lstrip('zeb')) # doesn't change anything as the argument passed doesn't match the beggining of the string
ththe left strip
>>> print('ththe left strip'.lstrip('h')) # doesn't change anything as the argument passed doesn't match the beggining of the string
ththe left strip