Unnecessary delete statement in function¶
Passing a local variable to a
del statement results in that variable being removed from the local namespace. When exiting a function all local variables are deleted, so it is unnecessary to explicitly delete variables in such cases.
In the function below, the variable
x is assigned a value that is used for a calculation, and is then explicitly deleted before the function exits. In this case, the delete statement can be removed without changing the behavior of the function.
x = get_some_object()
del x # This del statement is unnecessary