"x == None" vs "x is None"

Random832 random832 at fastmail.com
Sun Jan 17 16:33:13 EST 2016


<paul.hermeneutic at gmail.com> writes:

> I prefer (x is None) and (x is not None).
>
> This matches the SQL concept of NULL.
>
> (X = NULL) is not valid since NULL is not a value and cannot be compared
> with anything.

The suitably generic SQL operator is "is (not) distinct from", in some
dialects of SQL [certainly if you're using NULL directly you can simply
use is/is not, but the "distinct from" operators can be used to compare
two expressions that may either or both be NULL.

"X is not distinct from Y" == "X = Y or X is NULL and Y is NULL"




More information about the Python-list mailing list