pretty strange behavior of "strip"

Robert Kern robert.kern at gmail.com
Thu Dec 4 18:45:06 EST 2008


Guy Doune wrote:
> Hi everybody,
> 
> Could it be a bug?????
> 
> Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> test=['03.html', '06.html', 'questions.html', '04.html', 
> 'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html']
>  >>> test
> ['03.html', '06.html', 'questions.html', '04.html', 'toc.html', 
> '01.html', '05.html', '07.html', '02.html', '08.html']
>  >>> test[4]
> 'toc.html'
>  >>> test[4].strip('.html')
> 'oc'
> 
> Can't figure out what is going on, really.

http://docs.python.org/library/stdtypes.html#str.strip

str.strip([chars])

     Return a copy of the string with the leading and trailing characters 
removed. The chars argument is a string specifying the set of characters to be 
removed. If omitted or None, the chars argument defaults to removing whitespace. 
The chars argument is not a prefix or suffix; rather, all combinations of its 
values are stripped:

 >>> '   spacious   '.strip()
'spacious'
 >>> 'www.example.com'.strip('cmowz.')
'example'

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list