Write a program to perform below operations on tuple:
  • Create a tuple with different data types.
  • Print tuple items.
  • Convert tuple into a list.
  • Remove data items from a list.
  • Convert list into a tuple.
  • Print tuple items.

Code

# create tuple with different data types
t1 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
t2 = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j')

# print tuple
print(t1)
print(t2)

# convert tuple to list
l1 = list(t1)
print("Tuple to list: ", l1)

# remove element from list
l1.remove(5)
print("List after removing element (5 removed): ", l1)

# convert list to tuple
t3 = tuple(l1)
print("List to tuple: ", t3)

# print tuple
print(t3)

Output