Python’s del
keyword deletes a set completely.
del set
The del
keyword does not take a parameter value.
# creating a setmyset = {"apple", "banana", "cherry"}# deleting the set using the del keyworddel mysetprint(myset) # this will raise an error because the set we created no longer exists
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.