I've always coded in the style of if not value
, however, a few guides have brought to my attention that while this style works, it seems to have 2 potential problems:
- It's not completely readable;
if value is None
is surely more understandable. - This can have implications later (and cause subtle bugs), since things like
[]
and0
will evaluate toFalse
as well.
I am also starting to apply this idea to other comparisons, such as:
if not value
vsif value is False
if not value
vsif value is []
And so goes the list...
The question is, how far do you go with the principle? Where to draw the line, while keeping your code safe?
Should I always use the if value is None
style no matter what?