When am I supposed to use del in python?
<p>So I am curious lets say I have a class as follows</p>

<pre><code>class myClass:
    def __init__(self):
        parts = 1
        to = 2
        a = 3
        whole = 4
        self.contents = [parts,to,a,whole]
</code></pre>

<p>Is there any benifit of adding lines </p>

<pre><code>del parts
del to
del a
del whole
</code></pre>

<p>inside the constructor or will the memory for these variables be managed by the scope?</p>

<p>One use is to delete specific keys from a dictionary.</p>

<pre><code>&gt;&gt;&gt;&gt; food = {"apple": True, "banana": False}
&gt;&gt;&gt;&gt; del food['banana']
&gt;&gt;&gt;&gt; import json
&gt;&gt;&gt;&gt; json.dumps(food)
'{"apple": true}'
</code></pre>

<p>I use it all the time for cleaning up dictionaries before converting them to JSON.</p>

python memory-management