Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

keyword
python
del
communitycreator

How to delete a set using the "del" keyword in Python

Onyejiaku Theophilus Chidalu

Overview

Python’s del keyword deletes a set completely.

Syntax

del set

Parameter value

The del keyword does not take a parameter value.

Code example

# creating a set 
myset = {"apple", "banana", "cherry"}

# deleting the set using the del keyword
del myset

print(myset) # this will raise an error because the set we created no longer exists
Deleting a set using the del keyword

Code explanation

The code above returns an error because myset, the set we tried printing in line 7, no longer exists. This is because we deleted it using the del keyword in line 5.

RELATED TAGS

keyword
python
del
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring