For example, if I have a variable which is initialized as None and later want to find out if it was set, I might want to check and see if it was still None. If it's not, I want to do something.
if a is not None:
do_something()
If I rewrite that as:
if not a:
do_something()
do_something will also be called if a was initialized, but to a blank string, which was not the intention. Lots of types have some concept of a "false" value. As /u/steve_no points out in another comment: 0, '', [], {}, midnight all evaluate to False.
15
u/pbaehr Jun 23 '14
Depends. Could yield a false negative if a can be 0 or an empty string and that's not what you are interested in testing for.