Could someone explain this to a newbie

Michael Geary Mike at DeleteThis.Geary.com
Tue Apr 27 13:55:33 EDT 2004


Sean Berry wrote:
> >>> text = 'zone "southernpine.com" {'
> >>> text.lstrip("zone \"")
> 'southernpine.com" {'
>
> This is expected.
>
>
> >>> text = 'zone "newsouthpine.com" {'
> >>> text.lstrip("zone \"")
> 'wsouthpine.com" {'
>
> This is not.
>
> What happened to the ne...
>
> I suppose that is the secret, because I have
> tried with other words beginning with ne and
> they do not work either.

Sean, try this:

>>> text = 'abcabcaabbccaaabbbcccxyz'
>>> text.lstrip('abc')
'xyz'
>>>

Do you see what lstrip() really does now?

Your confusion is understandable. The documentation for lstrip() is very
poor--it does not make it at all clear what the function does. The argument
to lstrip() isn't a string that the function strips off, it is a *set of
characters* (expressed as a string) to strip off.

-Mike





More information about the Python-list mailing list