Remove the last element from Tuple Using negative indexing
Python3
# create a tuple tuple = ( "geeks" , "for" , "geeks" ) # remove last element tuple = tuple [: - 1 ] print ( tuple ) |
Output
('geeks', 'for')
Explanation:
Here instead of finding the index of the last element we directly write -1( that denotes the last element in the iterable) and then simply slicing it till the last element and update the existing tuple.
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.