Data Model

Delete Statements

del removes bindings, items, and attributes rather than producing a value.

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'}
BEFOREx[1, 2, 3]AFTER DEL Xx[1, 2, 3]
`del x` removes the name; the object survives if any other reference holds it, otherwise gets collected.

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

False

Notes

See also

Run the complete example

Example code

Expected output

{'name': 'Ada'}
['a', 'c']
False

Execution time appears here after you run the example.