split weirds

Robin Becker robin at jessikat.fsnet.co.uk
Thu Dec 14 15:11:30 CET 2000


In article <QI2l1FAXBMO6EwD6 at jessikat.demon.co.uk>, Robin Becker
<robin at jessikat.fsnet.co.uk> writes
>Can somebody explain why strip behaves differently with and without an
>argument?
>
>>>> from string import split
>>>> split(' ')
>[]
>>>> split(' ',' ')
>['', '']
>>>> split('  ')
>[]
>>>> split('  ',' ')
>['', '', '']
>>>> 
>
>with the default whitespace arg seems as though a run of whitespace is
>being treated as a single character.
several people have pointed out that arbitrary whitespace in the docs
means that so the no arg case really is special. I still find it a bit
strange that

split(' word ') ==> ['word'], but then the docs use the term separated
for the no arg case which can't be done for absent words. 
-- 
Robin Becker



More information about the Python-list mailing list