Behaviour of str.split

Raymond Hettinger vze4rx4y at verizon.net
Mon Apr 18 20:13:16 EDT 2005


[Will McGugan]
> >I'm curious about the behaviour of the str.split() when applied to empty
> >strings.
> >
> >"".split() returns an empty list, however..
> >
> >"".split("*") returns a list containing one empty string.

[John Machin]
> You are missing a perusal of the documentation. Had you done so, you
> would have noticed that the actual behaviour that you mentioned is
> completely the reverse of what is in the documentation!

Nuts!  I've got it from here and will get it fixed up.

<lament>
str.split() has to be one of the most frequently revised pieces of
documentation.  In this case, the two statements about splitting empty strings
need to be swapped.  Previously, all the changes occured because
someone/somewhere would always find a way to misread whatever was there.

In the absence of reading the docs, a person's intuition seems to lead them to
guess that the behavior will be different than it actually is.  Unfortunately,
one person's intuition is often at odds with another's.
</lament>


Raymond Hettinger





More information about the Python-list mailing list