Is None == None

Hi everyone. What is the difference between is None and == None ?? I have seen both used when checking for the presence of a node in a linked list ? I am familiar with the comparison operator but what the ■■■■ is “is”.

One compares equality, the other identity (is it the same object).
https://docs.python.org/3/reference/expressions.html#value-comparisons
https://docs.python.org/3/reference/expressions.html#is-not
You’ll see is used where you want to check if you are dealing with the same object or not (normally used for singletons like None) as suggested in PEP-8 https://www.python.org/dev/peps/pep-0008/#programming-recommendations.

1 Like