Fix Python – What is the difference between “is None” and “== None”

Question

Asked By – myusuf3

I recently came across this syntax, I am unaware of the difference.

I would appreciate it if someone could tell me the difference.

Now we will see solution for issue: What is the difference between “is None” and “== None”


Answer

The answer is explained here.

To quote:

A class is free to implement
comparison any way it chooses, and it
can choose to make comparison against
None mean something (which actually
makes sense; if someone told you to
implement the None object from
scratch, how else would you get it to
compare True against itself?).

Practically-speaking, there is not much difference since custom comparison operators are rare. But you should use is None as a general rule.

This question is answered By – Ben Hoffstein

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0