[Tutor] str.strip() help
john at fouhy.net
Thu Nov 2 03:11:10 CET 2006
On 02/11/06, Chris Hengge <pyro9219 at gmail.com> wrote:
> I can't figure out a way to .strip("string")
> Example might look like this:
> >>> 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.
>>> myStr = 'my words are what I want to strip'
>>> print myStr.strip('my')
words are what I want to strip
You can use .replace() to be more general.
>>> myStr = 'I want to strip my words'
>>> print myStr.replace('my', '')
I want to strip words
More information about the Tutor