# Not statements

#1

How do you use a not statement?

#2

A statement that contains the logical NOT operator would better describe it. Minor point.

The Boolean NOT is an operator that negates its operand. So, `not True` would be `False`, and vice versa.

The operator also has another less obvious use as a casting tool. The outcome is always a boolean, no matter what the operand.

``````not "A"  => False

not 0    => True
``````

It can do this because it is a unary operator that involves type casting (coercion/conversion). Above the not empty string would be cast to `True` initially, then negated. Likewise, the zero would be cast to `False` initially, then negated. It’s a two step process when the operand is not already a boolean.

It’s important to be able to recognize a boolean expression when we see it so in our own minds we already see the outcome as either True or False.

``````3 < 7 and not 5 > 4
``````

The reason being is so we learn precedence and get the operations in the correct order when evaluating it visually, and later when building up our own dynamic logic in code we write ourselves.

Comparisons are first priority in the above, and those are our first boolean expressions to evaluate.

``````3 < 7  => True
5 > 4  => True
``````

Rewriting, gives,

``````True and not True
``````

Next order of precedence is NOT, so

``````not True  =>  False
``````

and rewriting gives,

``````True and False
``````

which we know to be False, so that will be the final yield of the initial expression.

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.