Python example to add an Item to tuple

intTuple = (10, 20, 30, 40, 50)
print("Tuple Items = ", intTuple)
intTuple = intTuple + (70,)
print("Tuple Items = ", intTuple)
intTuple = intTuple + (80, 90)
print("Tuple Items = ", intTuple)
intTuple = intTuple[2:5] + (11, 22, 33, 44) + intTuple[7:]
print("Tuple Items = ", intTuple)

OUTPUT:

Tuple Items =  (10, 20, 30, 40, 50)
Tuple Items =  (10, 20, 30, 40, 50, 70)
Tuple Items =  (10, 20, 30, 40, 50, 70, 80, 90)
Tuple Items =  (30, 40, 50, 11, 22, 33, 44, 90)

Leave a Comment