bug in string.join()?

Joshua Marshall jmarshal at mathworks.com
Wed Feb 21 15:37:09 EST 2001


Thorsten Horstmann <thorsten at mats.gmd.de> wrote:
> "Fernando Rodrguez" wrote:
>> >>> string.join(("abcde"))
>> 'a b c d e'
>> 
>> Is this the expected behavior, or is it a bug? O:-)

> it's the expected behavior.
> string.join concatenate all sequence types. So it iterates
> over all characters in the string and joins them with the
> default separator ' '. 
> It's  not a bug - it's a feature!  ;-)

Also of note is that you have an unnecessary set of parens.  If you
meant to pass a tuple of one element into string.join, you needed to
add a trailing comma.  And you'd get a different behavior:

>>> string.join(("abcde"))
'a b c d e'
>>> string.join(("abcde",))
'abcde'



More information about the Python-list mailing list