Author PhoenixofMT
Recipients PhoenixofMT, docs@python
Date 2015-05-15.20:49:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1431722976.33.0.78521103066.issue24204@psf.upfronthosting.co.za>
In-reply-to
Content
This probably applies to all versions with the strip() method, but I'm using 3.4. Section 4.7.1 of the documentation has a poorly worded description/example for the behaviour of string.strip([chars]).

A casual reading of "The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped" lead me to believe this

>>> '0.0'.strip('.')
'0.0'

should be equivalent to the solution I found later

>>> '0.0'.replace('.', '')
'00'

The bit about [chars] requires recursive thinking ("are _stripped_") and clouds the fact that strip() iterates from beginning and end, discarding characters until it reaches a character that isn't in [chars].

In the example, it's not obvious (or wasn't to me) that the 'm' wasn't removed from 'example', and the missing periods gave the impression that they had been removed from the middle of the string instead of iterated to from the ends.

I can't think of a good way to rewrite the description, but perhaps you could borrow an example from rstrip() and add/replace:

>>> 'mississippi'.strip('mip')
'ssiss'

The glaring existence of that 'i' in the middle, when all others have been removed makes the limitation clear.

>>> '    hello world    '.strip()
'hello world'

Makes another good example.

Just trying to save someone else 20 minutes of confusion.
History
Date User Action Args
2015-05-15 20:49:36PhoenixofMTsetrecipients: + PhoenixofMT, docs@python
2015-05-15 20:49:36PhoenixofMTsetmessageid: <1431722976.33.0.78521103066.issue24204@psf.upfronthosting.co.za>
2015-05-15 20:49:36PhoenixofMTlinkissue24204 messages
2015-05-15 20:49:35PhoenixofMTcreate