Keywords and Control Flow
del — Delete bindings and items
Remove a name binding, attribute, item or slice, depending on the target. Name deletion does not necessarily destroy the object because other references may keep it alive. Attribute and item deletion are delegated to the target object through its deletion protocol. Multiple targets are processed left to right; an error can leave earlier deletions in effect. Missing dictionary keys raise KeyError, missing names raise NameError (including UnboundLocalError in applicable local scopes), and immutable built-in sequences do not support item deletion.
Formal Syntax & Structure
python syntaxpython
del namedel obj.attributedel container[key]del sequence[start:stop]Working Example
Example Snippetpython
numbers = [10, 20, 30, 40]alias = numbersdel numbers[1:3]print(alias)del numbersprint(alias)settings = {"debug": True, "limit": 5}del settings["debug"]print(settings)