How to add items in the tuple data structure

How to add items in the tuple data structure. This program can add an item in the tuple in a python data structure in python programming language. Using a while loop, append() adds items to a list. To make a while loop, use the syntax while condition:. Make a call list for each iteration. To add item s to the list, use append(object) until the condition is False.

tuplea = (12,45,42,65,67,87) 
print(tuplea)
tuplea = tuplea + (9,)
print(tuplea)
tuplea = tuplea[:5] + (23,44,56) + tuplea[:5]
print(tuplea)
listx = list(tuplea)
listx.append(45)
tuplea = tuple(listx)
print(tuplea)

 

Output:

(12, 45, 42, 65, 67,87)     

(12, 45, 42, 65, 67, 87, 9)

(12, 45, 42, 65, 67, 23, 44, 56, 12, 45, 42, 65, 67)

(12, 45, 42, 65, 67, 23, 44, 56, 12, 45, 42, 65, 67, 45)

What is tuples and how to add items in tuples

Tuples, unlike lists, are immutable, ordered lists of data. You may modify the contents of a list since it is changeable. Tuples are similar to Python lists, with one major exception: tuples cannot be modified. When you want a list to stay the same, you should use tuples.