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

+1 vote
by (157k 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')