Remove last element from Tuple Using lists
Python3
# create a list tu = ( 1 , 2 , 3 , 4 , 5 ) # remove last element tu = list (tu) tu.pop( - 1 ) tu = tuple (tu) print (tu) |
(1, 2, 3, 4)
Explanation:
As tuples are immutable we cannot directly modify them therefore first we convert it into lists then pop the last element.
Python program to remove last element from Tuple
Given a tuple, the task is to write a Python program to delete the last element in the tuple in Python.
Example:
Input: (“geeks”, “for”, “geeks”)
Output:(“geeks”, “for”)
Explanation: Here we are deleting the last element of the tuple and finally modifying the original one.