[Tutor] str.strip() help
chris.arndt at web.de
Thu Nov 2 16:57:01 CET 2006
John Fouhy schrieb:
> On 02/11/06, Chris Hengge <pyro9219 at gmail.com> wrote:
>>>>> myStr = "I want to strip my words."
>>>>> print myStr.strip("my")
>>>>> 'I want to strip words.'
> .strip() only removes text from the beginning and end of the string.
It is generally used to remove whitespace from the start/end of a string, e.g.
removing the newline character from the end of a line of text.
But you can also specify which characters to strip. Note that the argument is
not a string to strip off, but rather a collection of characters, any of which
should be stripped off, e.g.
>>> r = "I want to strip my words."
>>> r.strip('I. ') # note the space
'want to strip my words'
More information about the Tutor