adding elements to python tuples

U

Uwe Mayer

Hi,

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?

i.e. i have (1,2,3) and want to append 4:
(1,2,3,4) instead of ((1,2,3),4)

I wanted to use it as a return value of a function and an assignment, but:

(a,b,c),d = myfunc()

doesn't look nice to me. I intended to have

a,b,c,d = myfunc()

Thanks for any suggestions.
Ciao
Uwe
--
 
E

Erik Max Francis

Uwe said:
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:
(1, 2, 3, 4, 5)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,946
Members
47,498
Latest member
yelene6679

Latest Threads

Top