[Tutor] Is "var = None" in Python equivalent to "Set var

Danny Yoo dyoo at cs.wpi.edu
Mon Jun 30 01:28:58 CEST 2008


> As I understand it there are no cases where obj==None and obj is None
> will give different results

I hate going off track, but:

######################################
class CounterExample:
    def __eq__(self, other):
        return True

print "is?", CounterExample() is None
print "==", CounterExample() == None
######################################

That being said, this is an evil and perverse example.

In any case, setting something to None might not be such a bad thing.
'del someVariable', on the other hand, is almost always a bad code
smell.  It's much too low level; it's evidence that the code is not
taking advantage of simple mechanisms like functions or local
variables.


More information about the Tutor mailing list