+2 votes
in Programming Languages by (17.0k 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

0 votes
by (28.9k points)

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')