#create a tuple
tuplex = (2, 2, 1, 81, 30, 1)
print(tuplex)
#tuples are immutable, so you can not add new elements
#using merge of tuples with the + operator you can add an element and it will create a new tuple
tuplex = tuplex + (4,)
print(tuplex)
#adding items in a specific index
tuplex = tuplex[:9] + (10, 20, 3) + tuplex[:4]
print(tuplex)
#converting the tuple to list
listx = list(tuplex)
#use different ways to add items in list
listx.append(10)
tuplex = tuple(listx)
print(tuplex)

Output :

(2, 2, 1, 81, 30, 1)
(2, 2, 1, 81, 30, 1, 4)
(2, 2, 1, 81, 30, 1, 4, 10, 20, 3, 2, 2, 1, 81)
(2, 2, 1, 81, 30, 1, 4, 10, 20, 3, 2, 2, 1, 81, 10)

Add a Comment

Add a Comment