only if you know for sure that variable is numeric. Suppose you have a variable that can be a number or None (a rather common occurrence, typically in case a of a numerical parameter that can be omitted)
if variable is None:
tests whether the variable received a number (or not),
if variable == 0.0:
tests something else altogether. In fact it really depends what you mean: if you want to test whether something evaluates to True, by all means use:
if variable:
But if you want to test whether a string is empty (but not None) just write it so.
Comment
Careful:
if variable == 0:
is equivalent to
if variable
only if you know for sure that variable is numeric. Suppose you have a variable that can be a number or None (a rather common occurrence, typically in case a of a numerical parameter that can be omitted)
if variable is None:
tests whether the variable received a number (or not),
if variable == 0.0:
tests something else altogether. In fact it really depends what you mean: if you want to test whether something evaluates to True, by all means use:
if variable:
But if you want to test whether a string is empty (but not None) just write it so.