3 ms·
There's a reason why "if x is None" is idiomatic when "if not x" is shorter: >>> x = '' >>> if x is None: ... print 'x is None' ... >>> if not x:
by sah 18y ago
There's a reason why "if x is None" is idiomatic when "if not x" is shorter:
>>> x = ''
>>> if x is None:
... print 'x is None'
...
>>> if not x:
... print 'x is empty'
...
x is empty
- yogipatel 18y agoGood point. I was only thinking of sequence types, and failed to see that it would break with strings. I also somehow forgot to include "not" in the if statements! Pretty sad for a first post...