if x: completely equivalent to testing for a logical truth value, yes.
From the if documentation documentation :
He selects only one of the sets, evaluating the expressions one by one until a true value is found (see the Logical operations section for determining true and false)
where the Boolean operations section describes how truth is determined. The bool() function follows the same rules:
Returns a boolean value, that is, one of the values True or False. x is converted using the standard validation procedure.
Documentation of standard types contains a section on verification of property rights :
Any object can be checked for true, for use in the if or while state or as an operand of boolean operations below.
not just inverts the same meaning of truth; therefore, if x is considered to be the above rule, not x returns False and True otherwise.
Be careful: in Python 2, the built-in names False and True can be masked by setting the global:
>>> True = False >>> True False
and thus, t113 tests may be deceived by this reassignment. Python 3 makes the keywords False and True .
You do not need to use the utility function bool(x) is True or bool(x) is False . All you need is bool(x) and not bool(x) , since they already create True and False objects. bool() and not cannot return anything else using is True or is False , this is extremely redundant.
Last but not least, try not to reinvent the test wheel. The standard Python library comes with the unittest library; it has the functions assertTrue and assertFalse , and the implementation of these functions uses only if and if not .