How to Add Items in Tuple in Python

Add items in python tuple. 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.

Print Statement in Python

The print() function sends a message to the screen or another standard output device. The message can be a string or another object, which will be converted to a string before being displayed on the screen. To get the output and debug the code in Python, use the print() function. The supplied message or value is displayed on the console using this function.

List in Python

In Python, a list is a data structure that is a mutable (or changeable) ordered series of elements. A list’s items are the elements or values that make up the list. Lists are defined by values between square brackets [], much as strings are defined by characters between quotations. Multiple items can be stored in a single variable using lists. Lists are one of four built-in Python data structures for storing collections of data; the other three are Tuple, Set, and Dictionary, all of which have different properties and applications.

Tuples in Python

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. Using this program we can execute the add items in python tuple.

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


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