In this python tuple program, we will remove an item from a tuple.
Steps to solve the program
- Create a tuple.
- Now convert that tuple to a list using list().
- Remove the element from the list.
- Again convert the list to a tuple using tuple().
- Print the output.
tup = ('p','y','t','h','o','n')
print("Original tuple: ",tup)
l = list(tup)
l.remove('h')
tup = tuple(l)
print("After removing an element: ",tup)
Output :
Original tuple: ('p', 'y', 't', 'h', 'o', 'n')
After removing an element: ('p', 'y', 't', 'o', 'n')
1 thought on “Python tuple program to remove an item from a tuple”