Can we delete a tuple in Python?

Can we delete a tuple in Python?

Tuple can be deleted in Python. However, individual elements in a tuple cannot be deleted. 

del keyword is used to delete the tuple in Python.

The deletion can be done using the code below:

sites = "talenteve", "embeddeddesignblog", "py-programmers"
print(sites)
del(sites)
print(sites)

The above code prints the tuple sites first as ('talenteve', 'embeddeddesignblog', 'py-programmers')

For the next print statement, it throws below error as tuple sites is deleted using del(sites)

Traceback (most recent call last):
  File "D:\dharanidhar\eclipse-workspace\tuple-python\tuple.py", line 19, in <module>
    print(sites)
NameError: name 'sites' is not defined

---------------------

Access the #100 days of Python Coding challenge using below link:

Post a Comment

0 Comments