As a programmer, I generally try to avoid the del
statement because it is often an extra complication that Python program don't often need. However, when browsing the standard library (threading
, os
, etc...) and the pseudo-standard library (numpy
, scipy
, etc...) I see it used a non-zero amount of times, and I'd like to better understand when it is/isn't appropriate the del
statement.
Specifically, I'm curious about the relationship between the Python del
statement and the efficiency of a Python program. It seems to me that del
might help a program run faster by reducing the amount of clutter lookup instructions need to sift through. However, I can also see a world where the extra instruction takes up more time than it saves.
My question is: does anyone have any interesting code snippets that demonstrate cases where del
significantly changes the speed of the program? I'm most interested in cases where del
improves the execution speed of a program, although non-trivial cases where del
can really hurt are also interesting.