As a return value indicating absence of a result, None
is almost always better.
If you must use
False
, usenot my_var
. This assumes non -False
return values are never "falsy" (bool()
converts it intoFalse
- this is the case for empty strings, empty collections, and a few other things).If objects may be falsy but must be distinguished from
False
, then the comparison is necessary and you'll have to ignore the error (a minor variation,my_var is False
would be slightly more idiomatic, but it's virtually the same). But that's not a nice situation to be in and you should avoid it for the fake of clarity.
To repeat myself: If at all possible, use None
and test for my_var is None
.