TypeError: can only concatenate list (not "tuple") to list

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jan 4 03:27:59 EST 2010


En Mon, 04 Jan 2010 04:58:54 -0300, Chris Rebert <clp2 at rebertia.com>  
escribió:
> On Sun, Jan 3, 2010 at 11:51 PM, Gabriel Genellina
> <gagsl-py2 at yahoo.com.ar> wrote:

>> py> [1,2,3] + (4,5)
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>> TypeError: can only concatenate list (not "tuple") to list

Sorry, I inadvertedly posted an incomplete message. Note the last part:

>> In-place addition += does work:
>>
>> py> a = [1,2,3]
>> py> a += (4,5)
>> py> a
>> [1, 2, 3, 4, 5]

> Given that tuples are sometimes used as a poor man's object (i.e.
> collection of data fields), whereas lists are not typically used that
> way, I'd say it's probably a good thing an explicit type conversion is
> required here.

In that case += should not be allowed either...

-- 
Gabriel Genellina




More information about the Python-list mailing list