I can\'t really think of any reason why python needs the del
keyword (and most languages seem to not have a similar keyword). For instance, rather than deletin
When is del useful in python?
You can use it to remove a single element of an array instead of the slice syntax x[i:i+1]=[]
. This may be useful if for example you are in os.walk
and wish to delete an element in the directory. I would not consider a keyword useful for this though, since one could just make a [].remove(index)
method (the .remove
method is actually search-and-remove-first-instance-of-value).