Python's del Statement Removes Names, Not Objects, from Memory
A technical explainer on DEV Community clarifies a common misconception about Python's `del` statement among intermediate programmers. In Python, variables are names bound to objects, meaning multiple names can reference the same object simultaneously. When `del` is used on a name, it removes only that binding — the underlying object survives as long as at least one other name still points to it. A `NameError` is raised only when code tries to look up a name that no longer exists, not because the object itself was destroyed. The article notes that what happens when the very last reference to an object is deleted will be addressed in a follow-up piece.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in