Skip to Content

Python – Remove First Element From Tuple

In this tutorial, we will look at how to remove the first element from a tuple in Python with the help of some examples.

Tuples are immutable. That is, they cannot be altered after creating them. You can, however, create a copy of the tuple with the first element removed in Python.

Remove first element from a tuple in python

You can use a slice operation to slice only the part of the tuple you want. Let’s look at how to do this with the help of some examples.

To remove the first element from a tuple in Python, slice the original tuple from the second element (element at index 1) to the end of the tuple. This will result in a new tuple with the first element removed.

# create a tuple
t = (1, 2, 3, 4, 5)
# remove first element
t = t[1:]
print(t)

Output:

(2, 3, 4, 5)

The tuple now has the first element removed.

Please note that we are not modifying the original tuple. Instead, we are creating a new tuple with the first element removed and then assigning it back to the variable storing the original tuple.

If you want to store an ordered collection of objects and are expecting to make some changes to this collection (for example, adding, removing, replacing elements, etc.), you should prefer using lists that are much more flexible than tuples.

For example, you can use the list pop() function to remove an element from a list using its index.

# create a list
ls = [1, 2, 3, 4, 5]
# remove first element
ls.pop(0)
print(ls)

Output:

[2, 3, 4, 5]

Here, we used the list pop() function to remove the first element from a list. For more, refer to our detailed tutorial on removing the first element from a list in Python.

You might also be interested in –


Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.


Author

  • Piyush

    Piyush is a data scientist passionate about using data to understand things better and make informed decisions. In the past, he's worked as a Data Scientist for ZS and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.