str().join() isn't working

John Machin sjmachin at lexicon.net
Mon Aug 20 21:30:45 EDT 2007


On Aug 21, 4:34 am, kyoso... at gmail.com wrote:
> In your statement, your script tries to
> concatenate 2 lists to each other before it does the join, which is
> impossible in Python. The "+" operator is only for addition and for
> two or more strings.

Not so; the + operator is "for" *any* class which has an __add__
method:

>>> dir([])
['__add__', ... <snip>]
>>> a = [1,2,3]
>>> b = [4,5,6]
>>> c = a + b
>>> c
[1, 2, 3, 4, 5, 6]
>>> b += c
>>> b
[4, 5, 6, 1, 2, 3, 4, 5, 6]
>>> ('foo', 'bar') + (0, 1, 42, 666)
('foo', 'bar', 0, 1, 42, 666)
>>>

More than two strings? I don't think so; one + can have no more than
two operands.




More information about the Python-list mailing list