Does this Python expression make sense?

expression, logic, python

Solution

`variable` could be `0`, or `False`, or `[]`, or `()`; be 'falsy' in other words, and then the `if` statement would be skipped.

See Truth testing for more detail on what is considered false in a boolean context.

In short, testing if `variable is not None` allows `variable` to be anything else, including values that would otherwise be considered False in a boolean context.

Problem

I found this kind of expression several times in a python program: ``` if variable is not None: dothings(variable) ``` It seems strange to me, and I think that it has no more sense than: ``` if variable: dothings(variable) ``` Maybe I don't know Python enough, and the expression is explained somewhere?

Original source