Deleting your own variables
Found something new for you! So it turns out you can run this code:
def outer(x): del x return x outer(1) ''' Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in outer UnboundLocalError: local variable 'x' referenced before assignment '''
Not sure you'll want to add it to the list because it's unlikely anyone would do that - but it is technically interesting in itself because as far as I know Python is the only language that will let you destroy a local variable (or even function argument!) instead of just letting it expire and be garbage-collected when the current context is destroyed (like when leaving the function or an "except" block). By mistyping, you could easily delete a variable that should, by all means, be there and be left with a "wtf just happened to my poor dear x?" T_T
Also keep in mind that this can create very confusing scenarios, especially since the __del__() special method can be implemented in any class. Think about this: you try to del x from inside your method - except that the actual __del__() function is never called - because it is not called when del is issued but when all reference counts are extinguished and the instance is garbage-collected. So if you pass x to a function as a parameter, it will still have (at least) one reference holding the instance in memory outside of the function itself!
I'll let you come up with a clever, fun code example to show this if you think that this is worthy of adding to the your list :)