+2 votes
in Programming Languages by (73.8k points)
edited by
I have a tuple like ('a','b'). I want to add more elements to the existing tuple. How can I do?

1 Answer

+2 votes
by (348k points)
selected by
 
Best answer

You need to make the second element a 1-tuple and then you can append to the existing tuple. Here are examples:

>>> t=('a','b')
>>> t=t+('c',)
>>> t
('a', 'b', 'c')
>>> t=t+('d',)
>>> t
('a', 'b', 'c', 'd')

 


...