adding elements to python tuples

Erik Max Francis max at alcyone.com
Mon Jan 19 12:32:26 CET 2004


Uwe Mayer wrote:

> is it possible to append new elements to a tuple? I know tuples are
> immutable and that this would mean to create a new tuple with one more
> element, but how do you do it?

Just use the + operator:

>>> a = (1, 2, 3)
>>> a + (4,)
(1, 2, 3, 4)
>>> a
(1, 2, 3)
>>> a += (4, 5)
>>> a
(1, 2, 3, 4, 5)

-- 
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Here day fights with night.
    -- (the last words of Victor Hugo)



More information about the Python-list mailing list