strip not working on strings?

Pierre Quentel quentel.pierre at wanadoo.fr
Sun Nov 13 22:37:07 CET 2005


dan.j.weber at gmail.com a écrit :
> I'm using Python 2.3.5 and when I type the following in the interactive
> prompt I see that strip() is not working as advertised:
> 
> 
>>>>s = 'p p:p'
>>>>s.strip(' :')
> 
> 'p p:p'
> 
> Is this just me or does it not work? I want to get rid of all ' ' and
> ':' in the string. I've checked the doc and from what I can tell this
> is what strip() is supposed to do. Thanks for any help.
> 

strip(chars) "returns a copy of the string with leading and trailing 
characters removed", that is, at the beginning and at the end of the string

You can use this to remove the specified characters :

for char in chars:
     s.replace(char,'')

Pierre



More information about the Python-list mailing list