Data Model
Delete Statements
Deleting a dictionary key mutates the dictionary. The key is gone; it has not been set to None.
Source
profile = {"name": "Ada", "temporary": True}
del profile["temporary"]
print(profile)Output
{'name': 'Ada'}Deleting a list item removes that position and shifts later items left.
Source
items = ["a", "b", "c"]
del items[1]
print(items)Output
['a', 'c']Deleting a name removes the binding from the current namespace. It is different from rebinding the name to None.
Source
value = "cached"
del value
print("value" in locals())Output
FalseNotes
delremoves bindings or container entries.- Assign
Nonewhen absence should remain an explicit value. - Use container methods such as
pop()when you need the removed value back.
See also
- prerequisite: Variables
- prerequisite: Dictionaries
- shared mechanism: Mutability
Run the complete example
Expected output
{'name': 'Ada'}
['a', 'c']
False
Execution time appears here after you run the example.