How to Remove Items From Tuple in Python


In this example we will show how to remove items from the tuple in Python.

Source Code

my_tuple = ('a', 'b', 'c', 'd')

# Tuples are unchangeable, so you cannot remove items from it,
# but you can delete the tuple completely
del my_tuple

print(type(my_tuple))    # this will raise an error because the tuple no longer exists

Output:

Traceback (most recent call last):
  File "demo.py", line 7, in 
    print(type(my_tuple))    # this will raise an error because the tuple no longer exists
NameError: name 'my_tuple' is not defined
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments